Is this a bug report?
Yes
Did you try recovering your dependencies?
There are no dependencies to recover, the whole folder is deleted after the installation fails
$ npm —version
6.9.0
Which terms did you search for in User Guide?
«Error: Cannot find module ‘chalk'»
Environment
Environment Info:
System:
OS: Windows 10
CPU: x64 Intel(R) Core(TM) i5-4460 CPU @ 3.20GHz
Binaries:
Yarn: 1.15.2 — C:Program Files (x86)Yarnbinyarn.CMD
npm: 6.9.0 — C:Program Files (x86)nodejsnpm.CMD
Browsers:
Edge: 42.17134.1.0
Internet Explorer: 11.0.17134.1
npmPackages:
react: Not Found
react-dom: Not Found
react-scripts: Not Found
npmGlobalPackages:
create-react-app: Not Found
Steps to Reproduce
With node v.10.15.2 and npm 6.9.0
- npx create-react-app appName
Expected Behavior
All the dependencies are installed, the React App is created so that i can run it
Actual Behavior
The creation fails with this output
Creating a new React app in D:applicationstestsecommerceclient.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
yarn add v1.15.2
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.7: The platform "win32" is incompatible with this module.
info "fsevents@1.2.7" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@1.2.4: The platform "win32" is incompatible with this module.
info "fsevents@1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 5 new dependencies.
info Direct dependencies
├─ react-dom@16.8.5
├─ react-scripts@2.1.8
└─ react@16.8.5
info All dependencies
├─ fork-ts-checker-webpack-plugin@1.0.0-alpha.6
├─ react-dev-utils@8.0.0
├─ react-dom@16.8.5
├─ react-scripts@2.1.8
└─ react@16.8.5
Done in 141.38s.
internal/modules/cjs/loader.js:583
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:22:18)
at Object.<anonymous> (D:applicationstestsecommerceclientnode_modulesreact-dev-utilschalk.js:10:13)
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)
Aborting installation.
node has failed.
Deleting generated file... node_modules
Deleting generated file... package.json
Deleting generated file... yarn.lock
Deleting client/ from D:applicationstestsecommerce
Done.
I want to create a web app with Vue 3 and use UI Framework Vuesax version 4.
I’m trying to use vuesax@next (4.x) with Vue 3 and when I execute
npm install vuesax@next
I got an error
npm ERR! code 1
npm ERR! path C:UsersGame launcherDocumentsKrewkrew-appnode_modulesvuesax
npm ERR! command failed
npm ERR! command C:WINDOWSsystem32cmd.exe /d /s /c node scripts/postinstall.js
npm ERR! node:internal/modules/cjs/loader:936
npm ERR! throw err;
npm ERR! ^
npm ERR!
npm ERR! Error: Cannot find module 'chalk'
npm ERR! Require stack:
npm ERR! - C:UsersGame launcherDocumentsKrewkrew-appnode_modulesvuesaxscriptspostinstall.jsnpm ERR! at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
npm ERR! at Function.Module._load (node:internal/modules/cjs/loader:778:27)
npm ERR! at Module.require (node:internal/modules/cjs/loader:1005:19)
npm ERR! at require (node:internal/modules/cjs/helpers:102:18)
npm ERR! at Object.<anonymous> (C:UsersGame launcherDocumentsKrewkrew-appnode_modulesvuesaxscriptspostinstall.js:2:15)
npm ERR! at Module._compile (node:internal/modules/cjs/loader:1101:14)
npm ERR! at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
npm ERR! at Module.load (node:internal/modules/cjs/loader:981:32)
npm ERR! at Function.Module._load (node:internal/modules/cjs/loader:822:12)
npm ERR! at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {npm ERR! code: 'MODULE_NOT_FOUND',
npm ERR! requireStack: [
npm ERR! 'C:\Users\Game launcher\Documents\Krew\krew-app\node_modules\vuesax\scripts\postinstall.js'
npm ERR! ]
npm ERR! }
npm ERR! A complete log of this run can be found in:
npm ERR! C:UsersGame launcherAppDataLocalnpm-cache_logs2022-05-28T15_23_21_860Z-debug-0.log
And when chalk is installed I got this error
npm ERR! code 1
npm ERR! path C:UsersGame launcherDocumentsKrewkrew-appnode_modulesvuesax
npm ERR! command failed
npm ERR! command C:WINDOWSsystem32cmd.exe /d /s /c node scripts/postinstall.js
npm ERR! C:UsersGame launcherDocumentsKrewkrew-appnode_modulesvuesaxscriptspostinstall.js:2npm ERR! const chalk = require('chalk')
npm ERR! ^
npm ERR!
npm ERR! Error [ERR_REQUIRE_ESM]: require() of ES Module C:UsersGame launcherDocumentsKrewkrew-appnode_moduleschalksourceindex.js from C:UsersGame launcherDocumentsKrewkrew-appnode_modulesvuesaxscriptspostinstall.js not supported.
npm ERR! Instead change the require of index.js in C:UsersGame launcherDocumentsKrewkrew-appnode_modulesvuesaxscriptspostinstall.js to a dynamic import() which is available in all CommonJS modules.
npm ERR! at Object.<anonymous> (C:UsersGame launcherDocumentsKrewkrew-appnode_modulesvuesaxscriptspostinstall.js:2:15) {
npm ERR! code: 'ERR_REQUIRE_ESM'
npm ERR! }
npm ERR! A complete log of this run can be found in:
npm ERR! C:UsersGame launcherAppDataLocalnpm-cache_logs2022-05-28T15_27_11_833Z-debug-0.log
For information:
npm install -g chalk
not working
How to fix this ?
Dharman♦
29.3k21 gold badges80 silver badges131 bronze badges
asked May 28, 2022 at 15:38
1
This still happens with Macbook M1 Pro in 2023 while using Vue.js. None of the solution, commands here or old Github dicussions was able to fix the issue. Seems like upgrading is not the solution. Only way is to downgrade like below:
nvm install v14.21.2
nvm use v14.21.2
And then this final touch command, otherwise you would need to define nvm use version every time again:
nvm alias default v14.21.2
Note: If you do not have nvm installed yet. You can install with this command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
answered Jan 23 at 10:14
ElmarElmar
1,23313 silver badges16 bronze badges
Содержание
- Error: Cannot find module ‘chalk’ #152
- Comments
- Cannot find module ‘chalk’ #13
- Comments
- Fix Vue container — Error: Cannot find module ‘chalk’ #113
- Comments
- Expected Behavior
- Current Behavior
- Possible Solution
- Steps to Reproduce
- Checklist before submitting
- Error: Cannot find module ‘chalk’ #1
- Comments
- Cannot find module ‘chalk’ #3
- Comments
Error: Cannot find module ‘chalk’ #152
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:
Help will be greatly appreciated. Thanks
The text was updated successfully, but these errors were encountered:
- 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 chalk in 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 chalk are 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
- 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
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.stagingacorn-. CHANGELOG.md’
Still without success(((( HELP.
removing NODE_ENV = production in Netlify worked for me, finally
Источник
Cannot find module ‘chalk’ #13
Howdy! This looks like an awesome tool, thank you!
I installed the module npm install -g a11y and it installed without issue.
However when I tried to run it: a11y http://www.google.com
I got the following:
I tried running npm cache clean which I found after a few google searches but it did not work.
Not sure if this is specific to me or is a wider problem.
Sorry to post an issue so quickly after you released it to the world!
The text was updated successfully, but these errors were encountered:
@arthurvr you were faster than me 👍
@addyosmani Might be worth to put out a patch release for this. Without the module is useless for now.
Thanks for the PR. I just pushed out a patch release which should include the fix for this. Confirmed working on my machine — does it work for others now?
Oh. Needs ‘each-async’ too.
Landed. I’m going to give this a few before pushing another patch release (had hoped Travis would catch any issues like this during testing — doh!).
Could folks verify master is working for them before we cut another a11y?
We’il need indent-string too right? It’s used in cli.js , so.
Landed that one too. I think it should be good now. Will keep this open a little longer for others to test master.
had hoped Travis would catch any issues like this during testing — doh!
Just a randomly upcoming though: but more tests here and there may be welcome then 😉
You all work fast! Thank you all.
It’s working for me and it is awesome.
Hello I recently updated npm and node and I tried to install the angular cli but Now nothing works even simple generate command on the angular cli doesn’t work
I have tried all the steps you guys mentioned as the cure:
`npm install chalk
npm install each-async
npm install indent-string`
please help
Источник
Fix Vue container — Error: Cannot find module ‘chalk’ #113
Currently, when attempting to build the project using docker-compose -f local.yml build && docker-compose -f local.yml up , the Vue container dies while trying to build the front-end.
Expected Behavior
Building and firing up the containers should be enough to let the Vue container serve at http://localhost:8080.
Current Behavior
Firing up the Vue container fails with Error: Cannot find module ‘chalk’ :
dev: Failed to exec dev script vue_1 | npm ERR! code ELIFECYCLE vue_1 | npm ERR! errno 1 vue_1 | npm ERR! c2c-vue@1.0.0 dev: `node build/dev-server.js` vue_1 | npm ERR! Exit status 1 vue_1 | npm ERR! vue_1 | npm ERR! Failed at the c2c-vue@1.0.0 dev script. vue_1 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above. vue_1 | npm WARN Local package.json exists, but node_modules missing, did you mean to install? vue_1 | vue_1 | npm ERR! A complete log of this run can be found in: vue_1 | npm ERR! /root/.npm/_logs/2017-09-13T16_15_20_703Z-debug.log»>
Possible Solution
When I manually cd into frontend, install the dependencies using npm install and run docker-compose -f local.yml up again, it works.
Steps to Reproduce
Check out the current master
git reset —hard origin/master
Remove all files and folders that are not explicitly tracked by Git (such as npm build files or modules)
sudo git clean -x -i -d
Build and start the docker containers
sudo docker-compose -f local.yml build && sudo docker-compose -f local.yml up
You should already see that the Vue container throws an error and exits.
When visiting http://localhost:8080/, you’ll get a Connection refused .
Thus, we need to install the npm dependencies manually
cd interface/frontend && npm install
Run sudo docker-compose -f local.yml up and visit localhost:8080 again — it should work now.
I’d appreciate any feedback — maybe I made a mistake while setting it up?
Checklist before submitting
- I have confirmed this using the officially supported Docker Compose setup using the local.py configuration and ensured that I built the containers again and they reflect the most recent version of the project at the HEAD commit on the master branch
- I have searched through the other currently open issues and am confident this is not a duplicate of an existing bug
- I provided a minimal code snippet or list of steps that reproduces the bug.
- I provided screenshots where appropriate
- I filled out all the relevant sections of this template
The text was updated successfully, but these errors were encountered:
Источник
Error: Cannot find module ‘chalk’ #1
Hi! I’m trying to use your workflow. On the step in your tutorial, when I try to execute «gulp» in my «angular» dir I get this warning message:
Error: Cannot find module ‘chalk’
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (. angularnode_modu
colors.js:1:80)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
Can’t understand what I’m doing wrong.
The text was updated successfully, but these errors were encountered:
That is weird, did you npm install on the angular folder?
When I try execute «npm install» on the angular folder I get this:
npm WARN unmet dependency c:web. angularnode_modulesgulp-testem
e_modulestestemnode_modulesexpressnode_modulesconnectnode_modulescook
arser requires cookie@’0.1.2′ but will load
npm WARN unmet dependency c:web. angularnode_modulesgulp-testem
e_modulestestemnode_modulesexpressnode_modulescookie,
npm WARN unmet dependency which is version 0.0.5
npm WARN unmet dependency c:web. angularnode_modulesgulp-testem
e_modulestestemnode_modulesexpressnode_modulesconnectnode_modulescook
arser requires cookie-signature@’1.0.5′ but will load
.
It seems to me that I did something wrong during installation.
I know it is not a best practice, but sometimes there can be issues with system permissions. I use Mac, so in Terminal adding sudo will force an action using system administrator powers.
At your own risk, try running sudo npm install —save-dev , this will jump over any permission issue you may have. Replace sudo with Windows runas .
I can only say «Damn windows» and then, I have no damn idea why it is complaining.
Try a «npm cache clean» before trying to install the packages.
Источник
Cannot find module ‘chalk’ #3
$ yarn start
yarn start v0.21.3
$ webpack —config vendor/webpack.config.js
module.js:471
throw err;
^
Error: Cannot find module ‘chalk’
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/home/gmaimunah/Documents/Ultimate Angular/Angular 2 Fundamental/angular2master/vendor/webpack.config.js:5:13)
at Module._compile (module.js:570:32)
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)
error Command failed with exit code 1.
The text was updated successfully, but these errors were encountered:
$ sudo npm install chalk
└─┬ chalk@1.1.3
├── ansi-styles@2.2.1
├── escape-string-regexp@1.0.5
├── has-ansi@2.0.0
└── supports-color@2.0.0
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.1: wanted <«os»:»darwin»,»arch»:»any»>(current: <«os»:»linux»,»arch»:»x64″>)
$ yarn start
yarn start v0.21.3
$ webpack —config vendor/webpack.config.js
module.js:471
throw err;
^
Error: Cannot find module ‘progress-bar-webpack-plugin’
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/home/gmaimunah/Documents/Ultimate Angular/Angular 2 Fundamental/angular2master/vendor/webpack.config.js:6:25)
at Module._compile (module.js:570:32)
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)
error Command failed with exit code 1.
]$ sudo npm install progress-bar-webpack-plugin
angular-fundamentals-seed@0.1.0 /home/gmaimunah/Documents/Ultimate Angular/Angular 2 Fundamental/angular2master
└─┬ progress-bar-webpack-plugin@1.9.0
├─┬ object.assign@4.0.4
│ ├─┬ define-properties@1.1.2
│ │ └── foreach@2.0.5
│ ├── function-bind@1.1.0
│ └── object-keys@1.0.11
└── progress@1.1.8
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.1: wanted <«os»:»darwin»,»arch»:»any»>(current: <«os»:»linux»,»arch»:»x64″>)
[gmaimunah@ghina-id angular2master]$ yarn start
yarn start v0.21.3
$ webpack —config vendor/webpack.config.js
build [====================] 100% 0.2 seconds
Build completed in 0.169s
[0] dll vendor 12 bytes <0>[built]
error Command failed with exit code 2.
Источник
Под D: Project FlaksStudy_front, после установки Vue Scaffold в официальном документе, выполните Vue, отображается как следующая ошибка
D:projectflaskStudy_front>vue -V
internal/modules/cjs/loader.js:583
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> (D:nvmv10.8.0node_globalnode_modules@vueclibinvue.js:6: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)
Попробуйте использовать NPM и пряжу, чтобы повторно установить его, и вы не можете решить эту проблему.
существоватьD:projectflaskStudy_frontПосле установки мела выполнение по-прежнему ошибка. Наконец, в соответствии с позицией в подсказке,D:nvmv10.8.0Установите Vue Scaffolder:
yarn add @vue/cli
Вернуться к d: project flockstudy_front, execute vue -v, может быть отображено нормально, решение проблем
d:projectflaskStudy_front>vue -V
3.0.1
If you’re a developer that works with Node JS and JavaScript libraries and frameworks like React, Vue, and Angular, then you might have encountered the «Error: cannot find module» error.
In this article, I’m going to show you how to fix the error.
Why the «Error: cannot find module» Occurs
This error occurs because of the following reasons:
- you’re trying to import an item from a module you don’t have installed in your project directory
- you’re importing some things from an outdated package
- you’re pointing to a file that does not exist
In the screenshot below, you can see that I’m getting the error:
I’m getting the error because I’m trying to import the freeCodeCamp icon from the react-icons package, which I don’t have installed.
import { FaFreeCodeCamp } from "react-icons/fa";
How to Fix the «cannot find module» Error
If you get this error, the solution is always in the error. The module (package) not found is always specified in the format «Module not found: Error: Can’t resolve ‘package name’ in ‘project directory».
In my case, I got it like this «Module not found: Error: Can’t resolve ‘react-icons/fa’ in ‘C:UsersuserDesktopProjectsAddress Locatoraddress-locatorsrc'».
To fix the error, you need to install the package that is absent in your project directory – npm install package-name
or yarn add package-name
.
In my case, I need to install the react-icons
package so the freeCodeCamp icon can be resolved. I’ll do that by running yarn add react-icons
.
Once I install the package and run the app, everything should successfully compile:
If you install the package but you still get the error, then follow the steps below:
- delete the node modules folder by running
rm -rf node_modules
- delete package.lock.json file by running
rm -f package-lock.json
- clean up the NPM cache by running
npm cache clean --force
- install all packages again by running
npm install
That should fix the error for you.
Conclusion
When you get the “cannot find module” error, or “module not found”, it means you’ve not installed the package you’re trying to use.
If the error occurs even if you have the package installed, then the fixes suggested in this article can help you out.
Thank you for reading.
Learn to code for free. freeCodeCamp’s open source curriculum has helped more than 40,000 people get jobs as developers. Get started