我在使用
next build
版本 next
运行 ^10.2.3
时遇到此错误。
我尝试删除 node_modules
和 .next
文件夹并重新运行 npm install && next build
,但没有成功。
Error: Cannot find module 'next/dist/shared/lib/constants.js'
type: 'Error',
code: 'MODULE_NOT_FOUND',
requireStack: [
'.next/server/pages/_document.js',
'/usr/local/lib/node_modules/next/dist/server/require.js',
'/usr/local/lib/node_modules/next/dist/server/load-components.js',
'/usr/local/lib/node_modules/next/dist/build/utils.js',
'/usr/local/lib/node_modules/next/dist/build/worker.js',
'/usr/local/lib/node_modules/next/dist/compiled/jest-worker/processChild.js'
]
尝试删除
.next
文件夹并再次运行。
通过在项目的根目录中运行以下命令来清除 npm 缓存:
npm cache clean --force
删除package-lock.json文件和node_modules文件夹。
通过运行重新安装依赖项:
npm install
重新启动 Next.js 开发服务器:
npm run dev
同时删除 .next 文件夹
从 package.json 中删除constants.js 就可以解决问题。