node.js package.json 启动脚本,babel-node:在 heroku 部署中找不到
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36781542/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
package.json start script, babel-node: not found on heroku deploy
提问by eagspoo
When I run heroku localor when I just do npm startlocally, my app builds and runs fine. However when I deploy to heroku, the app crashes saying it cannot find babel-node.
当我运行heroku local或仅在npm start本地运行时,我的应用程序构建并运行良好。但是,当我部署到 heroku 时,应用程序崩溃了,说它找不到 babel-node。
Here is the log output:
这是日志输出:
2016-04-21T22:20:44.320025+00:00 heroku[api]: Deploy 5d9a9da by [email protected]
2016-04-21T22:20:44.320084+00:00 heroku[api]: Release v9 created by [email protected]
2016-04-21T22:20:44.542062+00:00 heroku[slug-compiler]: Slug compilation started
2016-04-21T22:20:44.542069+00:00 heroku[slug-compiler]: Slug compilation finished
2016-04-21T22:20:44.501025+00:00 heroku[web.1]: State changed from crashed to starting
2016-04-21T22:20:46.278065+00:00 heroku[web.1]: Starting process with command `npm start`
2016-04-21T22:20:50.467407+00:00 app[web.1]:
2016-04-21T22:20:50.467434+00:00 app[web.1]: > [email protected] start /app
2016-04-21T22:20:50.467435+00:00 app[web.1]: > babel-node index.js
2016-04-21T22:20:50.467436+00:00 app[web.1]:
2016-04-21T22:20:50.479490+00:00 app[web.1]: sh: 1: babel-node: not found
2016-04-21T22:20:50.521936+00:00 app[web.1]:
2016-04-21T22:20:50.538822+00:00 app[web.1]: npm ERR! Linux 3.13.0-79-generic
2016-04-21T22:20:50.539334+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-04-21T22:20:50.539595+00:00 app[web.1]: npm ERR! node v5.10.1
2016-04-21T22:20:50.555119+00:00 app[web.1]: npm ERR! npm v3.8.3
2016-04-21T22:20:50.555339+00:00 app[web.1]: npm ERR! file sh
2016-04-21T22:20:50.555549+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2016-04-21T22:20:50.555769+00:00 app[web.1]: npm ERR! errno ENOENT
2016-04-21T22:20:50.555965+00:00 app[web.1]: npm ERR! syscall spawn
2016-04-21T22:20:50.556142+00:00 app[web.1]: npm ERR! [email protected] start: `babel-node index.js`
2016-04-21T22:20:50.556305+00:00 app[web.1]: npm ERR! spawn ENOENT
2016-04-21T22:20:50.556488+00:00 app[web.1]: npm ERR!
2016-04-21T22:20:50.556666+00:00 app[web.1]: npm ERR! Failed at the [email protected] start script 'babel-node index.js'.
2016-04-21T22:20:50.556854+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2016-04-21T22:20:50.557017+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the qc-server package,
2016-04-21T22:20:50.557175+00:00 app[web.1]: npm ERR! not with npm itself.
2016-04-21T22:20:50.557343+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2016-04-21T22:20:50.557564+00:00 app[web.1]: npm ERR! babel-node index.js
2016-04-21T22:20:50.557741+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2016-04-21T22:20:50.557916+00:00 app[web.1]: npm ERR! npm bugs qc-server
2016-04-21T22:20:50.558110+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2016-04-21T22:20:50.558306+00:00 app[web.1]: npm ERR! npm owner ls qc-server
2016-04-21T22:20:50.558492+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2016-04-21T22:20:50.563859+00:00 app[web.1]:
2016-04-21T22:20:50.567790+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-04-21T22:20:50.568004+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2016-04-21T22:20:51.824822+00:00 heroku[web.1]: State changed from starting to crashed
2016-04-21T22:20:51.808246+00:00 heroku[web.1]: Process exited with status 1
My package.json:
我的 package.json:
{
"name": "qc-server",
"version": "1.0.0",
"description": "xxxx",
"main": "index.js",
"scripts": {
"test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js 'test/**/*.js'",
"test:watch": "npm run test -- --watch -G",
"start": "babel-node index.js"
},
"babel": {
"presets": [
"es2015"
]
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-cli": "^6.6.0",
"babel-core": "^6.6.0",
"babel-eslint": "^5.0.0",
"babel-preset-es2015": "^6.6.0",
"chai": "^3.5.0",
"chai-immutable": "^1.5.3",
"eslint": "^2.2.0",
"eslint-config-airbnb": "^6.0.2",
"eslint-plugin-react": "^4.1.0",
"mocha": "^2.4.5"
},
"dependencies": {
"express": "^4.13.4",
"immutable": "^3.7.6",
"node-uuid": "^1.4.7",
"redux": "^3.3.1",
"socket.io": "^1.4.5"
}
}
Anyone have suggestions?
有人有建议吗?
回答by Ricardo Souza
You have to include the dependency in you package.json so it will install it when you deploy.
您必须在 package.json 中包含依赖项,以便在部署时安装它。
$ npm install babel-cli -S
Than you have to change you startcommand to be like:
比你必须改变你的start命令是这样的:
"start": "babel-node index.js"
See herefor more info on deploying babel on heroku.com.
有关在 heroku.com 上部署 babel 的更多信息,请参见此处。
Warning: using babel-node is not recommended in production
警告:不建议在生产中使用 babel-node
回答by Toan Tran
I got the same issue, but I think set NPM_CONFIG_PRODUCTION=falseto install devDependencieswill be better. I used below command:
我遇到了同样的问题,但我认为设置NPM_CONFIG_PRODUCTION=false安装devDependencies会更好。我使用了以下命令:
heroku config:set NPM_CONFIG_PRODUCTION=false
回答by Raymond Wachaga
Specifically, include the necessary dependency under 'dependencies' and not 'devDependencies' in your 'package.json file'. This is because Heroku prunes (removes) your 'devDependencies' once it completes its build process, leaving only the 'dependencies', to keep the app as lean as possible.
具体来说,在“package.json 文件”中的“dependencies”而不是“devDependencies”下包含必要的依赖项。这是因为 Heroku 在完成构建过程后会修剪(删除)您的“devDependencies”,只留下“依赖项”,以保持应用程序尽可能精简。
This causes errors if you've built your NodeJS app using ES6 modules and included the necessary dependencies under 'devDependencies' instead of 'dependencies', namely the '@babel/' family of dependencies.
如果您使用 ES6 模块构建 NodeJS 应用程序并在“devDependencies”而不是“dependencies”下包含必要的依赖项,即“@babel/”依赖项系列,这会导致错误。
Update
更新
You should always build your NodeJS App before you deploy it so that you are always running the production build in the live environment which executes much faster with fewer resources.
您应该始终在部署之前构建您的 NodeJS 应用程序,以便您始终在实时环境中运行生产构建,该环境以更少的资源执行得更快。

