简体   繁体   English

从Heroku上的Rails应用程序运行npm软件包

[英]Run npm package from rails app on heroku

In my rails application I have a module that is running the following: 在我的rails应用程序中,我有一个运行以下命令的模块:

system("osmtogeojson #{input_path} > #{output_path}")

This works on my local machine as I have that specific npm package (osmtogeojson) installed. 这在我的本地计算机上有效,因为我安装了特定的npm软件包(osmtogeojson)。 I have my application deployed on Heroku, and I cannot get Heroku to install NPM or my NPM Packages. 我已经在Heroku上部署了我的应用程序,但是我无法让Heroku安装NPM或NPM软件包。

I follow the tutorial here and added a packages.json along with running 我在这里按照教程进行操作并在运行时添加了packages.json

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

and creating a .buildpacks file with: 并使用以下命令创建一个.buildpacks文件:

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

When I deploy to Heroku, I don't see it running npm install with my dependencies, and my code that's calling the npm package does not work. 当我部署到Heroku时,我没有看到它在依赖项的情况下运行npm install,并且调用npm软件包的代码不起作用。 What am I doing wrong here? 我在这里做错了什么?

This article is a little outdated. 本文有点过时了。 You don't need anything like heroku-buildpack-multi anymore to configure multiple buildpacks. 您不再需要heroku-buildpack-multi类的东西来配置多个buildpack。 Besides, this project is deprecated. 此外,不建议使用此项目。 Remove it from your app and just add official buildpacks heroku/nodejs and heroku/ruby . 从您的应用程序中删除它,只需添加官方的buildpacks heroku/nodejsheroku/ruby It is usually a good idea to add nodejs first. 首先添加nodejs通常是一个好主意。 Then try to re-deploy your application. 然后尝试重新部署您的应用程序。

If it does not work, try to login into your application dyno with heroku run bash and verify that you actually have package.json. 如果不起作用,请尝试使用heroku run bash登录到应用程序dyno,并验证您是否确实具有package.json。 Check if it is not ignored somewhere, like in .gitignore or .slugignore . 检查它是否在某处未被忽略,例如.gitignore.slugignore

If it still does not work, it is possible that you added required package as dev dependency. 如果仍然无法使用,则可能已将必需的软件包添加为dev依赖项。 If so, set config variable NPM_CONFIG_PRODUCTION to false . 如果是这样,请将配置变量NPM_CONFIG_PRODUCTION设置为false

Hope this helps. 希望这可以帮助。

I thought I had done this in the first place, but for the record this is what worked. 我本来以为是这样做的,但从记录来看,这是行得通的。

  • In my repo I ran and walked through the steps for $npm init 在我的仓库中,我运行并逐步完成了$npm init的步骤
  • Added the npm package I needed with $npm install osmtogeojson --save 使用$npm install osmtogeojson --save添加了我需要的npm软件包
  • Added my buildpack to heroku $heroku config:add heroku/nodejs 将我的buildpack添加到heroku $heroku config:add heroku/nodejs
  • Pushed my repo up to heroku $git push heroku master 将我的仓库$git push heroku master送到heroku $git push heroku master

Now it works! 现在可以了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM