Deploy nodejs issue on CF/BlueMix

867 views Asked by At

When I try to deploy the following repo to CF/BlueMix I got errors for the "devDependencies":

Error: Cannot find module 'webpack' 

If I add webpack to the dep I got error

Error: Cannot find module 'postcss-cssnext'

and continue for other dev dep....

Which part of the devDependencies , does the deploy shouldn't install only the "prod" dependency?

This is the repo: https://github.com/Hashnode/mern-starter

I run the build locally with npm run bs and I put in the manifest.yml the following

---
applications:
- name: myapp
  buildpack: nodejs_buildpack
  memory: 512M
  command: npm run start:prod
  services:
    - mong

what could be the reason of faliing on devdependencies ?

1

There are 1 answers

11
Chris Snow On

Are you pushing to Bluemix with the node_modules folder in your project? If you are, try deleting it entirely and repushing.

Also,

Just add the line node_modules in your .cfignore file to ignore the node_modules directory. The buildpack will run node install in your cloud foundry container. Also I'd recommend you to do a cf delete to remove it from cache and then do a cf push again

Source: See the comments from this question: unable to push node.js cloudant app to bluemix


Update

I think I have reproduced the problem:

2017-01-01T23:12:14.45+0000 [App/0]      ERR Error: Cannot find module 'webpack'
2017-01-01T23:12:14.45+0000 [App/0]      ERR     at Function.Module._resolveFilename (module.js:339:15)
2017-01-01T23:12:14.45+0000 [App/0]      ERR     at Function.Module._load (module.js:290:25)
2017-01-01T23:12:14.45+0000 [App/0]      ERR     at Module.require (module.js:367:17)
2017-01-01T23:12:14.45+0000 [App/0]      ERR     at require (internal/module.js:16:19)
2017-01-01T23:12:14.45+0000 [App/0]      ERR     at Object.defineProperty.value (/home/vcap/app/dist/server.bundle.js:280:19)
2017-01-01T23:12:14.45+0000 [App/0]      ERR     at Object.<anonymous> (/home/vcap/app/dist/server.bundle.js:1930:17)
2017-01-01T23:12:14.45+0000 [App/0]      ERR     at Object.defineProperty.value (/home/vcap/app/dist/server.bundle.js:2074:31)
2017-01-01T23:12:14.45+0000 [App/0]      ERR     at __webpack_require__ (/home/vcap/app/dist/server.bundle.js:20:30)
2017-01-01T23:12:14.45+0000 [App/0]      ERR     at /home/vcap/app/dist/server.bundle.js:40:18
2017-01-01T23:12:14.45+0000 [App/0]      ERR     at Object.<anonymous> (/home/vcap/app/dist/server.bundle.js:43:10)
2017-01-01T23:12:14.45+0000 [App/0]      ERR     at Module._compile (module.js:413:34)
2017-01-01T23:12:14.45+0000 [App/0]      ERR     at Object.Module._extensions..js (module.js:422:10)
2017-01-01T23:12:14.45+0000 [App/0]      ERR     at Module.load (module.js:357:32)
2017-01-01T23:12:14.45+0000 [App/0]      ERR     at Function.Module._load (module.js:314:12)
2017-01-01T23:12:14.45+0000 [App/0]      ERR     at Module.require (module.js:367:17)

The webpack import issue seems to be with the file dist/server.bundle.js which for me was generated by the command npm run bs.

The dist folder is getting uploaded to Bluemix and appears to be getting imported when your app starts.

Can you exclude the dist folder in .cfignore and build it when your app is uploaded with cf push? I'm not sure if you add multiple commands in manifest.yml, e.g.

command: npm <<your_new_build_command>> && npm run start:prod

However, it looks as though whatever you do in your new build command (e.g. npm run bs:prod) only picks up production dependencies when it creates your dist folder.

If you can't run multiple commands from the manifest.yml, then you may need to change start:prod so that it also performs a build step for the production environment.

Update 2

You can ask the node buildpack to not cache modules and download them each time you push by using NODE_MODULES_CACHE: false, e.g.

applications:
- name: ...
  buildpack: nodejs_buildpack
  memory: 512M
  command: ...
  env:
     NODE_MODULES_CACHE: false