pwa: 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:$HEROKU_API_KEY@git.heroku.com/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:$HEROKU_API_KEY@git.heroku.com/webapp.git
    - git push heroku master
    - echo "Deployed to production server"
  environment: production
  when: manual
  only:
    - master

Help will be greatly appreciated. Thanks

About this issue

Most upvoted comments

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!!!

I think the problem is npm install skipping devDependencies when NODE_ENV=production. I fixed it with npm --production=false install

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.

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.

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')

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.