` next build
▲ Next.js 15.1.3
../api/dist/es/index.js
Module not found: Can’t resolve ‘fs’
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
./src/lib/api.ts
./src/app/_components/auth/registerForm.tsx
Build failed because of webpack errors
ELIFECYCLE Command failed with exit code 1.
`
这是报错。
{
"name": "@repo/api",
"type": "module",
"exports": {
"import": {
"types": "./dist/es/index.d.ts",
"default": "./dist/es/index.js"
}
},
"main": "./dist/cjs/index.js",
"module": "./dist/es/index.mjs",
"types": "./dist/cjs/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "bunchee -w --tsconfig tsconfig.build.json",
"dev": "tsx watch src/index.ts",
"dbm": "prisma migrate dev",
"dbp": "prisma db push",
"dbg": "prisma generate",
"test": "jest --runInBand --detectOpenHandles --forceExit --verbose"
},
这是honojs模块导出的package.json配置。
/// apps/web2/node_modules/@repo/api/dist/es/index.js
`import { hc } from ‘hono/client’;
import { swaggerUI } from ‘@hono/swagger-ui’;
import { cors } from ‘hono/cors’;
import { PrismaClient } from ‘@prisma/client’;
import jwt from ‘jsonwebtoken’;
import { z, OpenAPIHono, createRoute } from ‘@hono/zod-openapi’;
import { prettyJSON } from ‘hono/pretty-json’;
import { isNil, omit } from ‘lodash’;
import { randomBytes, scryptSync, timingSafeEqual } from ‘crypto’;
import { getRandomInt } from ‘@3rapp/utils’;
import { writeFile } from ‘fs’;
const appConfig = {
baseUrl: process.env.NEXT_PUBLIC_APP_URL ‘http://localhost:3000’,
apiUrl: process.env.NEXT_PUBLIC_APi_URL ${process.env.NEXT_PUBLIC_APP_URL}/api
};
const createClient = (options)=>hc(appConfig.baseUrl, options);
const prismaClientSingleton = ()=>{
return new PrismaClient();
};
const db = globalThis.prismaGlobal ?? prismaClientSingleton();
if (process.env.NODE_ENV !== ‘production’) globalThis.prismaGlobal = db;
const authConfig = {
jwtSecret: process.env.AUTH_JWT_SECRET || ‘hTVLuGqhuKZW9HUnKzs83yvVBitlwc5d0PNfJqDRsRs=’,
jwtExpiration: ‘5d’
};
// Helpers.
const s = 1000;`
这是在nextjs项目下看到的 honojs导出的js文件。 程序在dev开发模式下是可以运行的,nextjs上传的文件honojs也可以保存。但是build就会报错。