Sunday, 28 May 2017

Heroku fails to run 'gulp serve'

I'm starting to work on a project using Angular Full Stack generator from Yeoman. This generator is cool but uses a looot of stuff (webpack, gulp, babel, etc). The project runs fine in my localy but fails on Heroku Cloud. I've setup some sort of CI. Whenever I push changes, SempahoreCI runs some tests and then pushes to Heroku. Both in my machine and in sempahore VM everything seems to work fine. But when sempahore pushes to Heroku, I can see in heroku logs that it fails running some npm scripts.

I've tried many variations of npm scripts installing things in preinstall and postinstalll scripts but it keeps failling.

It seems to me that it fails when requiring babel-register... and then of course 'gulp build' fails too because it tries to use the file gulpfile.babel.js which uses es2015 features and it is not being transpiled (because requiring babel-register fails)... or something like that. But this is supposed to happen in the postinstall script, which is ran after 'npm install' so all dependencies should be installed (including babel stuff). What's wrong in my reasoning?

Thanks for all your help in advanced!

These are my npm scripts:

  "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"
  }

And this is the log from heroku.

In my dependencies I have:

{
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-polyfill": "^6.7.2",
"babel-runtime": "^6.6.1",
}

and in my 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",
}

This is part from the log on heroku when it fails.

> 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



via Pablitoo Menii

No comments:

Post a Comment