我有一个我刚刚构建的 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 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
命令进行 Assets 编译。
这是我修复它的方法:
我使用 buildpacks:add
命令将 Nodejs buildpack 添加到应用程序中:
heroku buildpacks:add --index 1 heroku/nodejs
这将在 buildpack 执行顺序中的第一个位置插入 Node.js buildpack,并将其前面的其他 buildpack 向下移动一个位置。
注意:应用主要语言的 buildpack 应该是最后添加的 buildpack。在这种情况下,Ruby
是我们的主要语言。
然后您可以查看应用程序的构建包:
heroku buildpacks
=== nameless-brushlands-4859 Buildpack
1. heroku/nodejs
2. heroku/ruby
注意:列表中的最后一个构建包将用于确定应用程序的进程类型。
您应该始终指定与您正在开发和测试的运行时相匹配的Node.js 版本、npm 版本 和yarn 版本 .在本地查找您的版本:
node --version
npm --version
yarn --version
现在,使用 package.json
的引擎部分指定 Node.js、npm version 和 的版本在 Heroku 上使用的 yarn 版本。
"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
就这些。
希望对您有所帮助
关于ruby-on-rails - Heroku:错误-/bin/sh:1:npm:部署到 Heroku 时未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63646069/