Error: unable to run browserify in production (Heroku)

Error: unable to run browserify in production (Heroku)

我在开发中设置了 Browserify,它运行良好。但是当我尝试将应用程序推送到 Heroku 时,推送失败。

remote: -----> Preparing app for Rails asset pipeline

remote: Running: rake assets:precompile

remote: rake aborted!

错误:

remote: BrowserifyRails::BrowserifyError: Unable to run node_modules/.bin/browserify. Ensure you have installed it with npm.

我可以确认 browserifypackage.json 中。

"browserify": "~10.2.4",
"browserify-incremental": "^3.0.1",

并且文件确实存在于该位置。

请注意,该应用程序最近已从 Webrick 的 运行 移至 Puma,但我在这里没有看到任何迹象表明这是一个问题。

我不太确定从哪里开始解决这个问题。任何人都可以就我下一步应该尝试什么或可能导致这种情况的原因分享建议吗?

这里是处理这个问题的方法:

配置 Heroku 以使用 multi-buildpack

heroku config:add BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git

创建 .buildpacks 文件

为多构建包创建 .buildpacks 文件以确保 node.js 在 ruby.[=39= 之前编译]

https://github.com/heroku/heroku-buildpack-nodejs
https://github.com/heroku/heroku-buildpack-ruby

使用 --save

安装 browserify

rake assets:precompile in heroku deploy 期望 browserify 安装在 .node_modules 目录中。因此,将其从 devDependencies 移至 dependencies。

npm uninstall browserify --save-dev
npm install browserify --save

现在再次尝试部署!

git push heroku master

现在应该可以了。

我今天有这个。这是对我有用的

  1. 按照已接受的答案将 browserify 更改为常规依赖项。
  2. 重新排序构建包以将 heroku/nodejs 放在第一位。

从此

更改package.json
"devDependencies": {
  "browserify": "^12.0.1",
   ...
}

对此

"dependencies": {
  "browserify": "^12.0.1",
  ...
}

重新排序构建包

heroku buildpacks 的初始输出是

1. heroku/ruby
2. heroku/nodejs

我也是

$ heroku buildpacks:remove heroku/ruby
$ heroku buildpacks:add heroku/ruby

改成了

1. heroku/nodejs
2. heroku/ruby

使用heroku buildpacks:add --index 1 heroku/nodejs.

heroku-buildpack-multi.buildpacks 文件的使用已被弃用。