在部署到AWS时,我得到了以下纱线错误

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" 
  }
}

当前回答

我在Ubuntu上也遇到了类似的问题,即使在最新版本安装了很多次Nodejs之后,它总是显示相同的旧Nodejs版本;我发现它每次都在安装类似的旧Debian包,甚至在执行apt-get update命令之后也是如此

最后,我通过清除旧的nodeJs,然后添加不同的存储库源代码,并按照如下方式正常安装新发行版的nodeJs:

sudo apt-get purge --auto-remove nodejs
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs

请在下面找到所有NodeJs发行版的列表 https://github.com/nodesource/distributions/blob/master/README.md

您可能会找到其他方法进行更新,但这个方法对我很有用。

其他回答

一个解决方案,就是一个黑客可以

yarn config set ignore-engines true

然而,如果你想要一个永久的解决方案是:

删除node_modules/, package-lock。Json & yarn.lock 再次运行yarn install或NPM I。

你可以试着忽略引擎:

$ yarn install—忽略引擎

OR

$ yarn global添加<你的应用>—忽略引擎

通过运行以下命令,你可以看到所有你可以忽略的内容:

$ yarn help | grep -- --ignore

--ignore-scripts     don't run lifecycle scripts
--ignore-platform    ignore platform checks
--ignore-engines     ignore engines check
--ignore-optional    ignore optional dependencies

有时您无法升级Node引擎(遗留项目、客户端需求等)。在这种情况下,我发现的解决方案是使用“选择性依赖解析”来降级有问题的版本,如Yarn中所述:

https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions/

{
  "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"
  }
}

注意“决心”部分。您可以强制这些包使用降级版本(与您的旧Node引擎兼容)。

您需要升级node的版本。

我也遇到了同样的问题。

如果你使用Homebrew运行:

brew update  # This updates Homebrew to latest version
brew upgrade node

如果你使用nvm运行:

nvm current node -v  # Checks your current version
nvm install <version>  # Example: nvm install 12.14.1

以上步骤请访问https://nodejs.org/en/download/

获取一个满足错误中的条件的版本,最新的版本应该可以工作。

更详细的演练:https://flaviocopes.com/how-to-update-node/

我在Ubuntu上也遇到了类似的问题,即使在最新版本安装了很多次Nodejs之后,它总是显示相同的旧Nodejs版本;我发现它每次都在安装类似的旧Debian包,甚至在执行apt-get update命令之后也是如此

最后,我通过清除旧的nodeJs,然后添加不同的存储库源代码,并按照如下方式正常安装新发行版的nodeJs:

sudo apt-get purge --auto-remove nodejs
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs

请在下面找到所有NodeJs发行版的列表 https://github.com/nodesource/distributions/blob/master/README.md

您可能会找到其他方法进行更新,但这个方法对我很有用。