2017-05-28 101 views
0

我開始使用Yeoman的Angular Full Stack generator進行項目。這個發生器很酷,但使用了一些東西(webpack,gulp,babel等)。該項目在我的本地運行良好,但在Heroku Cloud上失敗。我已經設置了某種CI。無論何時我推送更改,SempahoreCI都會運行一些測試,然後推送到Heroku。無論是在我的機器還是在sempahore虛擬機中,一切似乎都很好。但是當sempahore推向Heroku時,我可以在heroku日誌中看到它運行某些npm腳本失敗。Heroku無法運行'gulp serve'

我已經嘗試了npm腳本在預安裝和postinstalll腳本中安裝東西的許多變體,但它仍然令人失望。

在我看來,它需要babel-register時會失敗...然後當然'gulp build'也會失敗,因爲它會嘗試使用使用es2015功能的文件gulpfile.babel.js,並且它不是(因爲要求babel-register失敗)......或類似的東西。 但是這應該發生在postinstall腳本中,它是在'npm install'後運行的,因此應該安裝所有依賴項(包括babel的東西)。我的推理出了什麼問題?

感謝您的高級幫助!

這是我的新公共管理腳本:

"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上時,它失敗的一部分。

> [email protected] 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! [email protected] postinstall: `typings install && gulp build` 
     npm ERR! Exit status 1 
     npm ERR! 
     npm ERR! Failed at the [email protected] 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

發現它!在閱讀heroku documentation about devDependencies之後,我發現我的計算機,SempahoreCI虛擬機和herokus虛擬機之間的區別在於默認情況下,SempahoreCI虛擬機和我的電腦都安裝了devdependencies,因爲命令'npm install'的默認容器安裝了devDeps和代表。 但是它看起來像Heroku默認情況下只安裝依賴關係,除非你在你的Heroku虛擬機中設置了一個配置變量,正如文檔中指出的那樣。

將該變量設置爲false後,它工作正常。當然,我應該重新組織我的package.json,這樣就不會把我的devDeps安裝在生產環境中,因爲我只需要一些babel和webpack的東西來構建。

相關問題