在将代码部署到AWS时,我遇到了以下的yarn错误
error fs-extra@7.0.1: The engine "node" is incompatible with this module. Expected version ">=6 <7 || >=8". Got "7.0.0"
任何想法这将如何解决?如果我在package.json中指定引擎,这是否有效?
{
"engines" : {
"node" : ">=8.0.0"
}
}
在将代码部署到AWS时,我遇到了以下的yarn错误
error fs-extra@7.0.1: The engine "node" is incompatible with this module. Expected version ">=6 <7 || >=8". Got "7.0.0"
任何想法这将如何解决?{
"engines" : {
"node" : ">=8.0.0"
}
}
我建议按照错误信息所说的检查你的Node.js版本(node -v
)。升级Node.js最简单的方法是使用n
版本管理器:
$ npm install -g n
然后安装最新版本(n latest
)或LTS版本(n lts
)的Node。
{
"name": "project",
"version": "1.0.0",
"dependencies": {
"left-pad": "1.0.0",
"c": "file:../c-1",
"d2": "file:../d2-1"
},
"resolutions": {
"d2/left-pad": "1.1.1",
"c/**/left-pad": "^1.1.2"
}
}
sudo npm cache clean -f
sudo npm install -g n
sudo n 10.22.1
node -v => Should be on 10.22.1
请告诉我您需要的 Node 版本,这里只是举例使用了 10.22.1。
刚刚发现不仅需要升级node
,还需要安装它。
这将升级node到最新版本:
brew upgrade node
这将安装特定版本的node
:
nvm install 17.0.0
ignore-engines
告诉包管理器在安装包时忽略 package.json 文件中 engines 字段的内容。所以当您将 ignore-engine 设置为 true 时,基本上是告诉 Yarn 忽略此字段,并继续进行安装,而不管 Node.js。
engines
允许软件包作者声明需要哪些 Node 引擎才能正常运行。基本上,需要哪个 Node 版本。如果您忽略此指导,就有可能安装一个无法与您正在使用的 Node 版本一起工作的软件包,因为它依赖于您的 Node 版本不支持的功能。
所以我发现最好的解决方案是更新到推荐版本的 Node,如下所示:
卸载旧版本的 Node.js。此命令将删除旧的 Node.js 包及其任何相关依赖项。
sudo apt autoremove nodejs
添加不同的存储库源。这将把 NodeSource 包存储库添加到系统的源列表中。
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
从新的存储库安装Node.js。
sudo apt-get install -y nodejs
对于使用 asdf
并遇到此问题的任何人,您的 nodejs
插件版本应该升级和/或设置。
检查 asdf 插件版本:
▶ asdf current
nodejs 16.13.0 Not installed. Run "asdf install nodejs 16.13.0"
poetry 1.2.1 /Users/zack/.tool-versions
python 3.9.9 /Users/zack/.tool-versions
验证是否安装了最新版本:
▶ asdf install nodejs latest
nodejs 20.1.0 is already installed
将全局版本设置为最新版本:
▶ asdf global nodejs latest
验证集:
▶ asdf current
nodejs 20.1.0 /Users/zack/.tool-versions
poetry 1.2.1 /Users/zack/.tool-versions
python 3.9.9 /Users/zack/.tool-versions
对我来说,这之后一切都正常工作了。
yarn add <your_lib> --ignore-engines