克隆我创建的存储库并设置.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.
然而它告诉我的是不支持。
我不熟悉该错误并正在寻求指导。
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 版本也可以安装在不同的路径中。
(请注意,在执行以下解决方案后,您可能还需要删除文件夹.next
和node_modules
,并再次重新安装节点模块,例如yarn
或npm install
)。
如果您将存储库拉取到安装了不同 Node.js 版本的另一台计算机上:
解决方案:将 Node.js 更新到支持的版本。
如果您在不同的环境中构建存储库,其中引用了不同的 Node.js 版本(例如在 Webstorm 与单独的终端中):
解决方案:确保您使用的是正确的环境,或者使用正确的 Node.js 路径,或者更新 Node.js。
如果您使用不同的构建命令,这些命令指定或不指定特定 Node.js 安装的(绝对)路径:
/usr/bin/node ...
--> 使用特定 Node.js 安装的绝对路径。node ...
--> 使用 $PATH 环境变量中指定的节点安装,例如/home/(username)/.nvm/versions/node/v14.18.1/bin/node
。解决方案:修改构建脚本以使用正确的Node.js路径,或者更新所使用路径下的Node.js版本。
如果由于某种原因 Webstorm 中的构建设置丢失或中断,这显然有时会发生,例如在切换分支时:
(您可以通过尝试在单独的终端内构建来验证这一点。)
解决方案:修复 Webstorm 中的构建设置以使用正确的 Note.js 路径,或在使用的路径下更新 Node.js。
归档时间: |
|
查看次数: |
52013 次 |
最近记录: |