无法加载 next.config.js

Nic*_*ick 24 reactjs next.js

克隆我创建的存储库并设置.env.local文件后,运行npm i然后运行npm run dev。服务器启动,加载 env,.env.local但它立即失败,提示我以下内容:

error - Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error
Error: Not supported
    at Object.loadConfig [as default] (C:\Users\Nick\Desktop\rebuild\node_modules\next\dist\server\config.js:399:74)
    at async NextServer.loadConfig (C:\Users\Nick\Desktop\rebuild\node_modules\next\dist\server\next.js:110:22)
    at async NextServer.prepare (C:\Users\Nick\Desktop\rebuild\node_modules\next\dist\server\next.js:92:24)
    at async C:\Users\Nick\Desktop\rebuild\node_modules\next\dist\cli\next-dev.js:126:9
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! rebuild@0.1.0 dev: `next dev`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the rebuild@0.1.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Nick\AppData\Roaming\npm-cache\_logs\2021-10-29T19_47_30_427Z-debug.log
Run Code Online (Sandbox Code Playgroud)

NextJS 文档说:See the error message in your terminal where you started next to see more context.然而它告诉我的是不支持。

我不熟悉该错误并正在寻求指导。

Nic*_*ick 40

我最终卸载了 Node 以及与之相关的所有内容。使用 Node v14.0.0 重新安装,它似乎可以工作。

感谢你的帮助!


Nia*_*na 17

我通过升级到最新版本的nodeJS解决了这个问题


kca*_*kca 5

Error: Not supported出现此错误的原因可能是所安装的Node.js版本不受所使用的Next.js版本支持。

例如Next.js v12 不支持 Node.js v10

Node.js 最低版本已从 12.0.0 提高到 12.22.0,这是第一个支持原生 ES 模块的 Node.js 版本

出现这种版本差异的原因有多种,有时非常出乎意料,而且看起来“无中生有”,因为不仅可以安装“错误”的 Node.js 版本,而且不同的 Node.js 版本也可以安装在不同的路径中。

解决方案:

(请注意,在执行以下解决方案后,您可能还需要删除文件夹.nextnode_modules,并再次重新安装节点模块,例如yarnnpm install)。

1.不同电脑

如果您将存储库拉取到安装了不同 Node.js 版本的另一台计算机上:

解决方案:将 Node.js 更新到支持的版本。

2.环境不同

如果您在不同的环境中构建存储库,其中引用了不同的 Node.js 版本(例如在 Webstorm 与单独的终端中):

解决方案:确保您使用的是正确的环境,或者使用正确的 Node.js 路径,或者更新 Node.js。

3.不同的构建命令

如果您使用不同的构建命令,这些命令指定或不指定特定 Node.js 安装的(绝对)路径:

  • 例如/usr/bin/node ...--> 使用特定 Node.js 安装的绝对路径。
  • 例如node ...--> 使用 $PATH 环境变量中指定的节点安装,例如/home/(username)/.nvm/versions/node/v14.18.1/bin/node

解决方案:修改构建脚本以使用正确的Node.js路径,或者更新所使用路径下的Node.js版本。

4. 损坏的构建设置

如果由于某种原因 Webstorm 中的构建设置丢失或中断,这显然有时会发生,例如在切换分支时:

(您可以通过尝试在单独的终端内构建来验证这一点。)

解决方案:修复 Webstorm 中的构建设置以使用正确的 Note.js 路径,或在使用的路径下更新 Node.js。