NextJS 在构建时找不到模块constants.js

问题描述 投票:0回答:3

我在使用

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'
  ]
typescript build next.js build-error
3个回答
8
投票

尝试删除

.next
文件夹并再次运行。


1
投票

通过在项目的根目录中运行以下命令来清除 npm 缓存:

npm cache clean --force

删除package-lock.json文件和node_modules文件夹。

通过运行重新安装依赖项:

npm install

重新启动 Next.js 开发服务器:

npm run dev

同时删除 .next 文件夹


0
投票

从 package.json 中删除constants.js 就可以解决问题。

© www.soinside.com 2019 - 2024. All rights reserved.