babel-node没有在Heroku上安装 [英] babel-node is not getting installed on Heroku

查看:93
本文介绍了babel-node没有在Heroku上安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Heroku上将babel-node用于ES6语法,但是在部署时出现构建错误.它说"babel-node:未找到".我已经尝试在本地计算机上进行全新安装,并且可以正常运行. Package.json:

I'm using babel-node for ES6 syntax on Heroku, but I get a build error when I deploy. It says "babel-node: not found". I've tried a clean install on my local computer and it works perfectly. Package.json:

{
  "name": "secret",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "./node_modules/.bin/babel-node ./bin/www"
  },
  "engines": {
    "node": "7.5.0",
    "npm": "5.0.3"
  },
  "dependencies": {
    "babel-cli": "^6.24.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    ...
  }
}

感谢您的帮助! :)

2017-07-17T11:02:26.997876+00:00 heroku[web.1]: State changed from crashed to starting
2017-07-17T11:02:31.839278+00:00 heroku[web.1]: Starting process with command `npm start`
2017-07-17T11:02:38.074157+00:00 heroku[web.1]: State changed from starting to crashed
2017-07-17T11:02:38.062607+00:00 heroku[web.1]: Process exited with status 1
2017-07-17T11:02:37.865774+00:00 app[web.1]:
2017-07-17T11:02:37.865786+00:00 app[web.1]: > secret@0.0.0 start /app
2017-07-17T11:02:37.865787+00:00 app[web.1]: > babel-node ./bin/www
2017-07-17T11:02:37.865787+00:00 app[web.1]:
2017-07-17T11:02:37.936361+00:00 app[web.1]: sh: 1: babel-node: not found
2017-07-17T11:02:37.966452+00:00 app[web.1]: npm ERR! file sh
2017-07-17T11:02:37.966683+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-07-17T11:02:37.966931+00:00 app[web.1]: npm ERR! errno ENOENT
2017-07-17T11:02:37.967106+00:00 app[web.1]: npm ERR! syscall spawn
2017-07-17T11:02:37.967287+00:00 app[web.1]: npm ERR! secret@0.0.0 start: `babel-node ./bin/www`
2017-07-17T11:02:37.967430+00:00 app[web.1]: npm ERR! spawn ENOENT
2017-07-17T11:02:37.967588+00:00 app[web.1]: npm ERR!
2017-07-17T11:02:37.967733+00:00 app[web.1]: npm ERR! Failed at the secret@0.0.0 start script.
2017-07-17T11:02:37.967873+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2017-07-17T11:02:37.969151+00:00 app[web.1]:
2017-07-17T11:02:37.969374+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2017-07-17T11:02:37.969484+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2017-07-17T11_02_37_957Z-debug.log
2017-07-17T11:25:52.044791+00:00 heroku[web.1]: State changed from crashed to starting
2017-07-17T11:25:54.841341+00:00 heroku[web.1]: Starting process with command `npm start`
2017-07-17T11:25:57.407691+00:00 heroku[web.1]: Process exited with status 1
2017-07-17T11:25:57.413873+00:00 heroku[web.1]: State changed from starting to crashed
2017-07-17T11:25:57.310176+00:00 app[web.1]:
2017-07-17T11:25:57.310190+00:00 app[web.1]: > secret@0.0.0 start /app
2017-07-17T11:25:57.310191+00:00 app[web.1]: > babel-node ./bin/www
2017-07-17T11:25:57.310192+00:00 app[web.1]:
2017-07-17T11:25:57.316940+00:00 app[web.1]: sh: 1: babel-node: not found
2017-07-17T11:25:57.335019+00:00 app[web.1]: npm ERR! file sh
2017-07-17T11:25:57.335287+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-07-17T11:25:57.335517+00:00 app[web.1]: npm ERR! errno ENOENT
2017-07-17T11:25:57.335735+00:00 app[web.1]: npm ERR! syscall spawn
2017-07-17T11:25:57.335933+00:00 app[web.1]: npm ERR! secret@0.0.0 start: `babel-node ./bin/www`
2017-07-17T11:25:57.336095+00:00 app[web.1]: npm ERR! spawn ENOENT
2017-07-17T11:25:57.336280+00:00 app[web.1]: npm ERR!
2017-07-17T11:25:57.336449+00:00 app[web.1]: npm ERR! Failed at the secret@0.0.0 start script.
2017-07-17T11:25:57.336614+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2017-07-17T11:25:57.337985+00:00 app[web.1]:
2017-07-17T11:25:57.338232+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2017-07-17T11:25:57.338379+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2017-07-17T11_25_57_323Z-debug.log

推荐答案

有点晚了,但这是我认为您所缺少的:

A little bit late, but here is what I think you are missing:

步骤(1):终端中的npm install --save babel-cli babel-preset-env

Step (1): npm install --save babel-cli babel-preset-env in terminal

关于步骤1的注意事项:不要保存到开发人员,因为这将需要您设置NPM_CONFIG_PRODUCTION = false

Note on step 1: Do not save to dev as that will require you to set NPM_CONFIG_PRODUCTION=false

步骤(2):您无需添加babel样板或使用babelrc文件就无法编译任何内容.最简单的方法是在主应用程序文件夹中创建一个.babelrc文件.您的package.json所在的相同,并输入以下内容:

Step (2): You are not compiling anything to babel without adding in the babel boilerplate and or using a babelrc file. Easiest method is to make a .babelrc file in your main app folder, ie. same one your package.json is in and input the following:

 {
  "presets": ["env"]
}

关于步骤2的注意事项:使用环境预设时,您不需要babel-preset-es2015等

Note on step 2: With the usage of the env preset you do not need the babel-preset-es2015, etc

步骤(3):您现在可以使用babel-node运行代码,因此在您的情况下,请执行启动脚本,即. ./node_modules/.bin/babel-node ./bin/www

Step (3): You can now run your code using babel-node, so in your case execute your start script, ie. ./node_modules/.bin/babel-node ./bin/www

如果您需要了解预设逻辑的进一步指导,我建议通读NPM模块: https://www.npmjs.com/package/babel-preset-env

I suggest reading through the NPM module if you need further guidance understanding the preset logic: https://www.npmjs.com/package/babel-preset-env

此外,我建议使用像pm2这样的流程管理器.如果节点实例崩溃,这将使其保持活动状态.曾经使用过forever模块,但pm2更好.这是package.json内部启动脚本的示例:

Furthermore, I would suggest using a process manager like pm2. This allows your node instance to keep alive if it crashes. The forever module used to do this but pm2 is way better. Here is an example of a start script inside your package.json:

脚本":{ "start":节点./node_modules/.bin/pm2 start main.json --attach --env生产" }

"scripts": { "start": "node ./node_modules/.bin/pm2 start main.json --attach --env production" }

Procfile(请注意,我正在使用nginx,但是仅使用npm start可以正常工作):

Procfile (note, I am using nginx but just npm start would work fine):

web: bin/start-nginx npm start 
worker: node ./node_modules/.bin/pm2 start worker.json --attach

这将是带有args的main.json以使用babel-node(请注意,将实例保持为1,并且不要在Heroku中使用Web dyno进行分叉):

And here would be your main.json with args to use babel-node (note, keep instance to 1 and do not fork on a web dyno in Heroku):

main.json:

main.json:

{
  "name": "the_awesome",
  "script": "app.js",
  "instances": 1,
  "exec_mode": "cluster"
}

worker.json:

worker.json:

{
  "name": "worker",
  "script": "/app/lib/worker.js"
}

(4)如果您在集群模式下使用pm2,请在您的app.js和worker.js中添加一个require('babel-register')钩子.如果您不是在群集模式下使用pm2,或者只是不使用pm2,则可以直接使用babel-node运行.js或es6文件

(4) Add a require('babel-register') hook to your app.js and worker.js if you are using pm2 in cluster mode. If you are using pm2 not in cluster mode, or just not using pm2 then you can use babel-node directly to run your .js or es6 files

最后,要检查babel-node是否确实安装,可以执行以下操作:

Finally, to check if babel-node is really installed you can do the following:

 heroku run bash -a {name of your app}
 ls ./node_modules/.bin //babel-node should be present

祝你好运!

这篇关于babel-node没有在Heroku上安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆