我在将 Gatsby 项目的最新更改部署到 Netlify 时遇到问题。在本地启动和构建项目的命令工作正常。
问题来了:
error gatsby@3.6.0: The engine "node" is incompatible with this module. Expected version ">=12.13.0". Got "10.24.1"
这里是存储库和部署日志的链接:
https://github.com/simonxcode/simonxcode.com https://app.netlify.com/sites/simonxcode/deploys/60aeec1c22d2e5154232e488
我知道这个问题以前被问过很多次,但没有一个常见的解决方案对我有用。也许是我执行错误或遗漏了其他内容。
以下是我尝试过的解决方案:
从 How to ignore incompatible engine "node" error on installing npm dependencies with yarn? 执行 yarn --ignore-engines
在 .env
文件中设置节点变量(在仓库中不可见,因为 .gitignore
)来自 Setting Environment Variables for Node to retrieve
//.env file
NODE_ENV=development
从 The engine "node" is incompatible with this module 添加 "engine": { "node": ">=12.13.0"}
到 package.json
使用来自 The engine "node" is incompatible with this module 的 brew update
和 brew upgrade node
更新节点
注意 1:在更新 Homebrew 之前,我删除了 node_modules/
和 yarn.lock
文件
注意 2: 在执行 brew postinstall node
和 brew link --overwrite node
后,我在检查 node -v
时不再可以访问 node、yarn 或 gatsby, yarn -v
和 gatsby -v
答案 0 :(得分:0)
我能够通过在 Netlify 的部署设置中声明 Node 版本来解决这个问题。构建和部署环境变量是:
键:NODE_VERSION
值:12.13.0
Screenshot of Environment Variable
这里有更多关于如何管理 Netlify 依赖的信息。
https://docs.netlify.com/configure-builds/manage-dependencies/#node-js-and-javascript
最后,我在当前版本的 node(16.2.0) 中遇到了一些其他问题,所以现在将坚持使用 12.13.0。 ;)