我开始使用Yeoman的Angular Full Stack generator开展项目。这个发电机很酷但是使用了一些东西(webpack,gulp,babel等)。该项目在我的本地运行良好,但在Heroku Cloud上失败。我已经设置了某种CI。每当我推动更改时,SempahoreCI会运行一些测试,然后推送到Heroku。在我的机器和sempahore VM中,一切似乎都运行正常。但是当sempahore推送到Heroku时,我可以在heroku日志中看到它无法运行一些npm脚本。
我尝试了很多变种的npm脚本在preinstall和postinstalll脚本中安装东西,但它仍然存在问题。
在我看来,当它需要babel-register时失败...然后当然'gulp build'也失败了因为它试图使用文件gulpfile.babel.js使用es2015功能并且它没有被编译(因为要求babel-register失败)......或类似的东西。 但这应该发生在postinstall脚本中,该脚本在'npm install'之后运行,因此应该安装所有依赖项(包括babel的东西)。我的推理出了什么问题?
感谢您提供的所有帮助!
这些是我的npm脚本:
"engines": {
"node": "^6.10.1",
"npm": "^4.6.1"
},
"scripts": {
"test": "gulp test",
"preinstall": "npm install -g typings gulp-babel babel-preset-es2015",
"postinstall": "./node_modules/.bin/typings install && gulp build",
"update-webdriver": "node node_modules/protractor/bin/webdriver-manager update",
"start": "node dist/server"
}
这是来自heroku的日志。
在我的依赖项中,我有:
{
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-polyfill": "^6.7.2",
"babel-runtime": "^6.6.1",
}
和我的devDependencies:
{
"babel-core": "^6.24.1",
"babel-eslint": "^6.0.4",
"babel-loader": "^6.2.4",
"babel-plugin-transform-runtime": "^6.6.0",
"babel-preset-es2015": "^6.6.0",
"babel-register": "^6.6.5",
"gulp-babel": "^6.1.2",
}
这是heroku登录失败时的一部分。
> MyApp@0.0.0 postinstall /tmp/build_7f20844c396ed5a10eb776089fb204d5
> typings install && gulp build
[?25h
[20:39:23] Failed to load external module babel-register
[20:39:23] Failed to load external module babel-core/register
[20:39:23] Failed to load external module babel/register
/tmp/build_7f20844c396ed5a10eb776089fb204d5/gulpfile.babel.js:4
import _ from 'lodash';
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at execute (/tmp/build_7f20844c396ed5a10eb776089fb204d5/node_modules/gulp-cli/lib/versioned/^3.7.0/index.js:25:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! MyApp@0.0.0 postinstall: `typings install && gulp build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the MyApp@0.0.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /app/.npm/_logs/2017-05-28T20_39_23_227Z-debug.log
-----> Build failed
We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
If you're stuck, please submit a ticket so we can help:
https://help.heroku.com/
Love,
Heroku
! Push rejected, failed to compile Node.js app.
! Push failed
答案 0 :(得分:0)
将该变量设置为false后,它工作正常。当然我应该重新组织我的package.json,以便不是所有的devDep都安装在生产中,因为我只需要一些babel和webpack来构建。