Ruby on rails Heroku:错误-/bin/sh:1:npm:部署到Heroku时未找到
我有一个刚刚构建的Rails 6应用程序 但是,当我尝试使用以下命令行部署到Heroku时:Ruby on rails Heroku:错误-/bin/sh:1:npm:部署到Heroku时未找到,ruby-on-rails,heroku,npm,yarnpkg,Ruby On Rails,Heroku,Npm,Yarnpkg,我有一个刚刚构建的Rails 6应用程序 但是,当我尝试使用以下命令行部署到Heroku时: git push heroku master 经过一段时间后,我得到以下错误: yarn install v1.22.4 [1/4] Resolving packages... [2/4] Fetching packages... info fsevents@1.1.1: The platform "linux" is incompatible with
git push heroku master
经过一段时间后,我得到以下错误:
yarn install v1.22.4
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.1.1: The platform "linux" is incompatible with this module.
info "fsevents@1.1.1" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
$ npm run build
/bin/sh: 1: npm: not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
我已多次重新运行该命令,但仍然出现相同的错误。我终于解决了问题 问题是因为我没有Nodejs构建包来运行
npm run Build
命令进行资产编译
以下是我如何修复它的方法:
我使用buildpacks:add
命令将Nodejs buildpack添加到应用程序中:
heroku buildpacks:add --index 1 heroku/nodejs
这将在buildpack执行顺序的第一个位置插入Node.js buildpack,并将其前面的其他buildpack向下移动一个位置
注意:应用程序主要语言的构建包应该是最后添加的构建包。在本例中,Ruby
是我们的主要语言
然后,您可以查看应用程序的构建包:
heroku buildpacks
=== nameless-brushlands-4859 Buildpack
1. heroku/nodejs
2. heroku/ruby
注意:列表中的最后一个构建包将用于确定应用程序的进程类型
您应该始终指定与您正在开发和测试的运行时相匹配的Node.js版本、npm版本和纱线版本。要在本地查找您的版本,请执行以下操作:
node --version
npm --version
yarn --version
现在,使用package.json
的引擎部分指定要在Heroku上使用的Node.js、npm版本和纱线版本
"version": "0.1.0",
"engines": {
"node": "12.x",
"npm": "6.x",
"yarn": "1.x"
},
现在,您可以部署到Heroku,它将正常工作:
git add .
git commit -m "add nodejs buildpack"
git push heroku master
就这些
我希望这有帮助