1

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 ?

Chris Snow
  • 23,813
  • 35
  • 144
  • 309

1 Answers1

0

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
Community
  • 1
  • 1
Chris Snow
  • 23,813
  • 35
  • 144
  • 309
  • No I put it already in the .cf ignore -> node_modules/ , there is option to clear cache without delete ? –  Jan 01 '17 at 22:14
  • I'm not sure, however, this questions looks like it may help http://stackoverflow.com/questions/31006154/how-can-i-avoid-loading-buildpack-components-from-cache-on-bluemix – Chris Snow Jan 01 '17 at 22:19
  • and regard the issue which is trying to download the dev dep? any idea direction? Im stuck...Thanks! –  Jan 01 '17 at 22:21
  • have you tried setting the `--production` flag or `NPM_CONFIG_PRODUCTION=true` https://github.com/cloudfoundry/nodejs-buildpack/issues/16 – Chris Snow Jan 01 '17 at 22:30
  • How can I do it you please give example? I try in the manifest to put also env: NODE_ENV: production which doesnt help... –  Jan 01 '17 at 22:37
  • Do you have any bluemix instance maybe you can clone the repo and do the steps it taks 3-5 min maybe you will have any direction ...Thanks for the support! –  Jan 01 '17 at 22:38
  • Hi thanks for effort 1+ , do you mean run the npm run bs & npm run start:prod together ? if so the commands(in the yaml) cannot get two attributes ? (maybe the sequence matter ) ,btw did you able to run it ? –  Jan 02 '17 at 07:58
  • I've updated the answer with some more information. I think you need a new build command that builds `dist` without the devDependencies. – Chris Snow Jan 02 '17 at 08:59
  • as workaround I put all the dev dependencies inside the dependency and still its not working, this should solve the issue (as quick workaround ) ? –  Jan 02 '17 at 09:19
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/132084/discussion-between-chris-snow-and-rayn-d). – Chris Snow Jan 02 '17 at 11:11
  • Did you able to run it in your machine ? –  Jan 02 '17 at 15:14