pwa
pwa copied to clipboard
Error: Cannot find module 'chalk'
Hey guys (@jeffposnick and all) am getting this error on my Heroku App after CI/CD from GitLab to Heroku. Following is the gitlab-ci.yml script:
image: node:6
stages:
- ver
- init
- tests
- deploy
cache:
paths:
- node_modules/
ver:
stage: ver
script:
- node --version
- whoami
init:
stage: init
script:
- npm install -g chalk
- npm cache clean
- rm -rf node-modules
- npm install
run_tests:
# needed for testing selenium on docker with java
image: karthikiyengar/node-nightwatch:0.0.1
stage: tests
script:
- sudo npm install
- sudo npm test
deploy_staging:
stage: deploy
script:
- npm install -g chalk
- npm cache clean
- rm -rf node-modules
- npm install
- git remote add heroku https://heroku:[email protected]/webapp-staging.git
- git push heroku master
- echo "Deployed to staging server"
environment: staging
only:
- master
deploy_production:
stage: deploy
script:
- npm install -g chalk
- npm cache clean
- rm -rf node-modules
- npm install
- git remote add heroku https://heroku:[email protected]/webapp.git
- git push heroku master
- echo "Deployed to production server"
environment: production
when: manual
only:
- master
Help will be greatly appreciated. Thanks
- Do you see this error locally, or just in the Heroku environment?
- Can you provide some more context, such as the stack trace associated with that error message?
- At what stage in the CI process does the error occur?
- And I see several instances of
npm install -g chalkin your config—did you deliberately add those in to attempt to fix the error, or are those needed for something else?
Hi @jeffposnick thanks for responding to this.
- I encountered the issue only on Heroku and not locally
- From my findings I discovered that Heroku doesn't install devDependencies. But even at that, after moving all the dependencies into production, I couldn't fire the app.
- It builds and deploys successfully on GitLab, but I get the error when I try to view the App on Heroku.
- The several
npm install -g chalkare as a result of my attempt to fix the problem.
This happened to me about 10 mins ago while installing the PWA template.
I had to turn off local-npm (an npm caching program). Sometimes local-npm can't find packages. It could be a package caching bug with Heroku.
@MichaelJCole please how did you achieve this? I mean turning off the local-npm
Hey @nwaughachukwuma local-npm is a project I use when travelling so nvm is cached locally and I'm not using mobile data. https://www.npmjs.com/package/local-npm
If you haven't installed it, then that's probably not the problem. It's possible there is a proxy server in the way that is caching/proxying incorrectly. The simplest thing that could possibly work is to delete node_modules or use a different version of node/nvm.
Also happens on a direct PWA template deployment to Heroku, no local-npm installed. I believe it is caused because Heroku runs app as PRODUCTION env (and specifically prunes dev modules), and Chalk is listed under devDependencies.
The reason is build/build.js uses chalk. It may be moved into main dependencies, or made optional in build.js depending on NODE_ENV (just make sure you do this before forced process.env.NODE_ENV = 'production')
I confirm @lifecoderua theory. It's happening on pwa and webpack... and maybe any other vue template
@nwaughachukwuma any solution to this yet? I just deployed to heroku and receiving the same error.
-
dev/build works on my local env but as soon as I deploy to heroku the logs throw an error.
2018-07-16T10:11:47.171884+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" request_id=48b2c643-3c7c-4802-a066-bad93d00b546 fwd="105.186.163.232" dyno= connect= service= status=503 bytes= protocol=https -
I did run an npm install to make sure all depencies are installed.
-
npm run build results in
throw err;
^
Error: Cannot find module 'chalk'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/app/build/check-versions.js:2:15)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
- I did run npm install chalk -g to no effect.
I have also faced the same problem.
I just deleted my node_modules folder and did npm install.
It worked for me. Hope it will work for you also.
In thesis, build should not be run using production environment. This is bad practice on CI/CD and I think it is the way the CLI generated script expects us to work. We run build in dev and use the dist on production.
I know is not the best thing in the world, but that was how I solved that before.
The other option is to change webpack files (I think build.js) to receive production env for build mode.
I were able to do that with 2 lines. Currently, there's no build parametrization for production (or at least it did not have that when I tweaked the webpack files).
I'm just returning here to expose these 2 solutions I used on my issue some months ago.
I was having this issue with hosting a Vue SPA on Heroku. I was able to fix this issue with adding "postinstall": "npm run build" in the scripts object in the package.json , and I also had NODE_ENV=production. Not sure if it helps with the PWA issue as I have not tested it personally. All I know is it was able to run the build command correctly after Heroku cleared out all the node_modules and reinstalled them. Hope this helps!
I think the problem is npm install skipping devDependencies when NODE_ENV=production. I fixed it with npm --production=false install
ATTENTION!!!
still doesnt work. still returning "Cannot find module 'chalk'".
I tried:
-npm install -g chalk
-npm --production=false install
-npm cache clean
-tryed to delete node_modules, returning OPERATION NOT PERMITTED,ISTAT
'\node_modules\.staging\acorn-...\CHANGELOG.md'
Still without success(((( HELP!!!
removing NODE_ENV = production in Netlify worked for me, finally
I think the problem is
npm installskipping devDependencies whenNODE_ENV=production. I fixed it withnpm --production=false install
works for me ! thanks!
I had the same issue with netlify.
For the lazy:
if [ "$NODE_ENV" == "production" ]; then
echo "installing node_modules for production in dev mode"
NODE_ENV=development npm install
# or: NODE_ENV=development yarn install
fi
I'm not sure this is a good idea, but otherwise how should we build the project for production without devDependencies?