when I m running sails -v, sails lift or even installing npm I m getting this error Please help —
Error: Cannot find module 'commander'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/usr/local/lib/node_modules/sails/bin/_commander.js:6:15)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
asked Mar 20, 2018 at 20:11
Most likely commander
is missing from package.json
. Install it and add it to package.json
by doing:
npm install commander --save
answered Mar 20, 2018 at 21:47
ralphtheninjaralphtheninja
124k20 gold badges108 silver badges120 bronze badges
Install commander
globally.
sudo npm install commander -g
- This will install commander module under
/usr/lib/node_modules/
.
answered Aug 23, 2019 at 15:59
ahmnouiraahmnouira
9499 silver badges6 bronze badges
Uninstalling sails and reinstalling with 'sudo'
resolved it.
npm uninstall sails -g
sudo npm install sails -g
answered Mar 22, 2018 at 7:20
DonDon
5051 gold badge4 silver badges14 bronze badges
1
When i try setup new app with the help of express-generator.
given error:Cannot find module ‘commander’
Node version:12.16.1
switch node version :10.16.3
after switch node version is working fine..
answered Mar 12, 2020 at 19:21
In my case it was because of bad version of node. I’ve tried node 8.15.1 and it works.
answered Jul 31, 2019 at 14:49
IiskaandarIiskaandar
3942 silver badges7 bronze badges
On my end, after doing npm install
, and attempt to run npm run watch
I encountered this same issue of Error: Cannot find module 'commander'
.
I did below:
// delete node_modules (can do manually) or command below
// rm -rf node_modules
npm install
And I was able to do npm run watch
again.
This maybe because of corrupted packages.
Dharman♦
29.3k21 gold badges80 silver badges131 bronze badges
answered Oct 26, 2021 at 3:29
josevoidjosevoid
5175 silver badges12 bronze badges
When changing into a directory with a .node-version file I get the following error.
11:26:36 ▶ cd kibana
module.js:549
throw err;
^
Error: Cannot find module 'commander'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/engarcia/.avn/bin/_avn:5:15)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
I’ve installed avn via yarn which worked fine previously. I’ve tried blowing out avn with rm -r ~/.avn
and reinstalling as well with yarn global add avn avn-nvm
to no avail.
Details
- avn
avn --version
— 0.2.3 - node
node --version
— 8.11.1 - nvm
nvm --version
— 0.33.8 - n
n --version
— na - zsh
zsh --version
— na - bash
bash --version
— 4.4.19(1)-release
The output of __avn_debug
in the directory with a .node-version
file is:
11:24:48 ▶ __avn_debug module.js:549 throw err; ^ Error: Cannot find module 'commander' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at Object.<anonymous> (/Users/engarcia/.avn/bin/_avn:5:15) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3)
avn
is loaded in my ~/.bashrc
file with:
[[ -s "$HOME/.avn/bin/avn.sh" ]] && source "$HOME/.avn/bin/avn.sh" # load avn
nvm specific
- As an
nvm
user I am confirming that I did not install with Homebrew
Содержание
- Error: Cannot find module ‘commander’ #76
- Comments
- Footer
- Cannot find module ‘commander’ #5
- Comments
- How to fix npm cannot find module error
- Level up your programming skills
- About
- Error: Cannot find module commands #349
- Comments
- Report a bug?
- What is the current behavior?
- What is the expected behavior?
- Error: Cannot find module ‘commander’ about sass-fundamentals HOT 2 OPEN
- Comments (2)
- Related Issues (18)
- Recommend Projects
- React
- Vue.js
- Typescript
- TensorFlow
- Django
- Laravel
- Recommend Topics
- javascript
- server
- Machine learning
- Visualization
- Recommend Org
- Microsoft
Error: Cannot find module ‘commander’ #76
When I try to run htmlhint , I get following error message:
The text was updated successfully, but these errors were encountered:
Try to update node to new version v4.1.2, then try reinstall htmlhint again.
npm install htmllint -g
Your node version is too old.
Ok. Do you know of any Ubuntu PPA that has Node v4.1.2 packaged? The only one I found did not advance much further than Ubuntu Trusty itself.
It seems your nodejs is not instal well,so the dependencie cannot finded.
My NodeJS installation is just the original package from Ubuntu. I did not modify anything.
@devurandom according to this page on nodejs.org there used to be an up-to-date PPA (Chris Lea’s), but it’s now transitioned into the NodeSource process, which I’m not sure how it works (it seems to be removing the PPA but not adding a new one). Anyway, if you follow the instructions on the nodejs.org page linked above, it should allow you to update node. You might have to remove your current installation first, or maybe NodeSource takes care of that. Try it out and see if it works for you 🙂
@waldyrious Thanks! After installing the current version of NodeJS, uninstalling all modules with npm uninstall and rm -fr
/.npm , then reinstalling htmlhint, it appears to work.
@devurandom great to hear 🙂 you can close this issue then.
© 2023 GitHub, Inc.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Источник
Cannot find module ‘commander’ #5
Running localicious gives me the following error:
The text was updated successfully, but these errors were encountered:
Thanks! We’re still working out the last kinks before we can release 1.0 to npm and a report like this is very helpful.
For me, it works when I go through the following steps:
- git clone git@github.com:PicnicSupermarket/localicious.git && cd localicious
- yarn install
- node bin/localicious
Can you share the steps that you went through that cause this failure for you?
Once we are done with the 1.0 (most likely before the end of next week) we will publish the tool to npm such that it can be installed globally.
Also not that the syntax of the Localicipe will still change a bit today/tomorrow as a result of #3.
The yarn install is missing from the Requirements and installation section so I didn’t run that.
When I now run it, it still fails.
Am I supposed to run it with localicious render ./copy.yaml or localicious render ./LocaliciousConfig.yaml ? Both result in different errors. I don’t have a file named copy.yaml but the docs mention this so I’m not sure if it’s supposed to be the output or input file.
When running localicious render LocaliciousConfig.yaml . —platforms android —languages en I get the following:
Contents of LocaliciousConfig.yaml:
I’ll update the Requirements and installation section, it is indeed still a placeholder.
As for your other question, we have two commands:
localicious render : Renders a Localicipe. A Localicipe is the YAML file that contains the copy. It should indeed look like what you posted above.
localicious install : Pulls a Localicipe from the source configured in the provided localicious config and renders it for the languages and platforms configured in the same file.
A LocaliciousConfig looks like this.
The error you are running into looks like a bug. If you change your Localicipe to the following, it should work:
Источник
How to fix npm cannot find module error
Posted on Jun 08, 2022
Learn how you can resolve the npm cannot find module error
JavaScript’s Node.js server supports module export and import in both ECMAScript modules and CommonJS format.
Sometimes, npm will throw an error saying Cannot find module because of module import as shown below:
Here’s the content of the index.js file:
The cannot find module error occurs because npm cannot find the module required by the index.js file. In this case, the axios module.
To resolve the error, you need to make sure that axios is installed in the node_modules/ folder.
Please note that the node_modules/ folder must be located in the same directory as the index.js file:
If you have run the npm install command before, then it’s possible that the installation of the module is incomplete or corrupted.
Delete the node_modules/ folder using the rm -rf node_modules command, then run npm install again. That may fix the issue.
Finally, the same error can happen when you require() a local .js file that can’t be found.
Suppose you have a file named lib.js placed in the same folder as the index.js file:
To import the file, you need to specify the correct path in the require() function.
The following code:
Will produce the same error:
This is because the require() function will always look inside the node_modules/ folder.
To let Node.js knows that you are importing a local file, use the absolute path as follows:
The ./ syntax means the root directory where you run the node command. In this case, the folder where index.js is located.
If you have a file one level down like this:
Then you need to adjust the require() path as shown below:
The same also applies when you use the ES modules format as follows:
To conclude, the error “Cannot find module” happens when Node.js can’t find the module that a file is trying to import.
You can see the file and the module that’s causing the issue from the error output generated by Node itself.
And that’s how you resolve the npm cannot find module issue. Great work! 😉
Level up your programming skills
I’m sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I’ll send new stuff straight into your inbox!
About
Nathan Sebhastian is a software engineer with a passion for writing tech tutorials.
Learn JavaScript and other web development technology concepts through easy-to-understand explanations written in plain English.
Источник
Error: Cannot find module commands #349
Report a bug?
What is the current behavior?
Published some updates on my package on npm and it is full broken.
Steps to reproduce:
- yarn global add vestigo
- vestigo scan —target=»https://127.0.0.1/» —method=»GET» -w
This does not happen with prior versions:
- yarn global add vestigo@0.0.5
- vestigo scan —target=»https://127.0.0.1/» —method=»GET»
This does not happen while debugging:
What is the expected behavior?
The command line is supposed to run like in prior versions
The text was updated successfully, but these errors were encountered:
Any ideas on what could be causing this issue?
Try installing with npm globally, yarn globally sometimes gets wonky.
Same thing is happening to me, it was working fine and then newer versions stopped working with that error.
I’m not using yarn.
It’s not generating any output into the lib directory. I have 3 commands, referencing other files under src/ and under another directory inside src/
Then I modify the file of one of the commands (just removing a line break), do npm pack and that file gets to the lib directory and into the packagle.
But then I run npm pack again withouit modifying any file and the lib is empty again
Weird thing is that the readme.md file and the help result is updated correctly
Never been able to solve it personally I just have to run in dev mode. This really hinders my project so I’m thinking to find an alternative
Found the problem @crimson-med !
There’s a file in my directory called tsconfig.tsbuildinfo, that keeps a signature of the files. Clearly if the file didn’t change then it doesn’t compile it again.I don’t know when or why that file appeared there, but deleting the file fixes the problem.
The issue is that it appears again after packaging it again. So what I did was to add the removal of that file to the postpack script. Maybe it should go into the prepack? I’m not sure but this works for now.
Now my postpack looks like this : «postpack»: «rm -f oclif.manifest.json tsconfig.tsbuildinfo»,
I tried that but it makes no difference for me @martinlarosa
@martinlarosa hi, thanks your idea. but this doesn’t seem to work for me.
«postpack»: «rm -f oclif.manifest.json tsconfig.tsbuildinfo»,
my package.json scripts:
this is yarn publish log,
The log shows its execution order
- run version script.
- run prepack script.
- run postpack script.
when executing yarn publish , the tsconfig.tsbuildinfo file may not be deleted when the prepack command was triggered.
so I try to delete the tsconfig.tsbuildinfo file in the prepack command.
here is updated package.json scripts:
its works for me..
@crimson-med If you are in the same situation as me, you can also try.
Источник
Error: Cannot find module ‘commander’ about sass-fundamentals HOT 2 OPEN
Upgrade to the latest Node version. It includes commander.
g-savitha commented on January 15, 2023
Upgrade to the latest Node version. It includes commander.
Doesn’t solve the issue. Still getting the same error
- Action required: Greenkeeper could not be activated 🚨
- Recommended documentation update to include minimum nodeJS version HOT 2
- ./run -e nesting command not working in windows command prompt/node command prompt HOT 3
- Challenge 6 theme-2 test is expecting incorrect values for non-primary buttons
- An in-range update of greenkeeper-lockfile is breaking the build 🚨 HOT 4
- [Windows 7] Problem when saving Sass file HOT 4
- An in-range update of chalk is breaking the build 🚨 HOT 1
- An in-range update of greenkeeper-lockfile is breaking the build 🚨 HOT 2
- An in-range update of commander is breaking the build 🚨 HOT 3
- More verbose logging on the exercise terminal
- Dependency deprecation warning: travis-deploy-once (npm) HOT 1
- ENOENT Error When Running ./run -e nesting
- Error: Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime (83)
- Upgrade in node version from v7.7.3 to v8.16 HOT 1
- npm ERR (node-sass: Command failed) after executing npm i HOT 5
- Dependency Dashboard
- Error: cannot run ‘chalk’
Recommend Projects
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
TensorFlow
An Open Source Machine Learning Framework for Everyone
Django
The Web framework for perfectionists with deadlines.
Laravel
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
Recommend Topics
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
server
A server is a program made to process requests and deliver data to clients.
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Visualization
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
Recommend Org
We are working to build community through open source technology. NB: members must have two-factor auth.
Microsoft
Open source projects and samples from Microsoft.
Источник
Error: Cannot find module ‘commander’ #76
Comments
devurandom commented Oct 8, 2015
When I try to run htmlhint , I get following error message:
The text was updated successfully, but these errors were encountered:
yaniswang commented Oct 9, 2015
Try to update node to new version v4.1.2, then try reinstall htmlhint again.
npm install htmllint -g
Your node version is too old.
devurandom commented Oct 9, 2015
Ok. Do you know of any Ubuntu PPA that has Node v4.1.2 packaged? The only one I found did not advance much further than Ubuntu Trusty itself.
yaniswang commented Oct 9, 2015
It seems your nodejs is not instal well,so the dependencie cannot finded.
devurandom commented Oct 9, 2015
My NodeJS installation is just the original package from Ubuntu. I did not modify anything.
waldyrious commented Oct 9, 2015
@devurandom according to this page on nodejs.org there used to be an up-to-date PPA (Chris Lea’s), but it’s now transitioned into the NodeSource process, which I’m not sure how it works (it seems to be removing the PPA but not adding a new one). Anyway, if you follow the instructions on the nodejs.org page linked above, it should allow you to update node. You might have to remove your current installation first, or maybe NodeSource takes care of that. Try it out and see if it works for you 🙂
devurandom commented Oct 9, 2015
@waldyrious Thanks! After installing the current version of NodeJS, uninstalling all modules with npm uninstall and rm -fr
/.npm , then reinstalling htmlhint, it appears to work.
waldyrious commented Oct 9, 2015
@devurandom great to hear 🙂 you can close this issue then.
Footer
© 2023 GitHub, Inc.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Источник
Cannot find module ‘commander’ #5
Comments
lammertw commented Oct 24, 2019
Running localicious gives me the following error:
The text was updated successfully, but these errors were encountered:
larslockefeer commented Oct 24, 2019 •
Thanks! We’re still working out the last kinks before we can release 1.0 to npm and a report like this is very helpful.
For me, it works when I go through the following steps:
- git clone git@github.com:PicnicSupermarket/localicious.git && cd localicious
- yarn install
- node bin/localicious
Can you share the steps that you went through that cause this failure for you?
Once we are done with the 1.0 (most likely before the end of next week) we will publish the tool to npm such that it can be installed globally.
Also not that the syntax of the Localicipe will still change a bit today/tomorrow as a result of #3.
lammertw commented Oct 24, 2019
The yarn install is missing from the Requirements and installation section so I didn’t run that.
When I now run it, it still fails.
Am I supposed to run it with localicious render ./copy.yaml or localicious render ./LocaliciousConfig.yaml ? Both result in different errors. I don’t have a file named copy.yaml but the docs mention this so I’m not sure if it’s supposed to be the output or input file.
When running localicious render LocaliciousConfig.yaml . —platforms android —languages en I get the following:
Contents of LocaliciousConfig.yaml:
larslockefeer commented Oct 24, 2019 •
I’ll update the Requirements and installation section, it is indeed still a placeholder.
As for your other question, we have two commands:
localicious render : Renders a Localicipe. A Localicipe is the YAML file that contains the copy. It should indeed look like what you posted above.
localicious install : Pulls a Localicipe from the source configured in the provided localicious config and renders it for the languages and platforms configured in the same file.
A LocaliciousConfig looks like this.
The error you are running into looks like a bug. If you change your Localicipe to the following, it should work:
Источник
5. Install MKDIRP, this module is used to create a directory.
E:Program Filesnodejsnode_modules>npm install mkdirp —save
npm WARN saveError ENOENT: no such file or directory, open ‘E:Program Filesnod
ejspackage.json’
E:Program Filesnodejs
`— [email protected]
`— [email protected]
This error occurs because the installation is not entered into the npm directory.
Enter cd /usr/local/node/lib/node_modules/npm
# npm install mkdirp —save
npm]# npm install mkdirp —save
+ [email protected]
updated 1 package and moved 1 package in 3.675s
NPM package installation is divided into local installation (Local), global installation (global), from the knocking command line, the difference is only the -g, such as:
npm install —save Write information into package.json while installing
-save-dev refers to the package information to DEVDependencies, indicating that the parcel you depend on time.
-save refers to the package information to Dependencies, indicating that you rely on the package.
For example, we will use Gulp when developing to compress our files. This is our Gulp package information will be added to DEVDependencies, and we publish compressed files when publishing, do not use Gulp.
Using the server built by NodeJS is sent frequently after the release, the information of the HTTP package is added to the DependenCIES area.
The following explanation.
1. When npm install xxx -g, the module will be downloaded to the [Global Directory].
[Global Directory] Sets via NPM Config Set Prefix «Directory Path».
Gets the current settings through NPM Config Get Prefix.
2. NPM Install XXX is the directory where the module is downloaded to the current command line.
Module Path responsible for formatting the picture name
responsible for processing an asynchronous perspective module async
Источник
How to solve «Error: Cannot find module ‘*.js’» with Node.js
Introduction
If you are trying to run your Node.js application and you get something like this:
then you are most likely trying to run the wrong file. It is possible you are missing a dependency that is needed from npm install , but if it says it cannot find the main file you are trying to run, then you are trying to run a file that does not exist. It is a common mistake.
How to fix «Error: Cannot find module»
You need to double check you are running the correct file from the correct directory. Here are some steps to diagnose.
General tips
Here are some general things to keep in mind when diagnosing the issue:
- Make sure you are in the correct directory.
- Make sure you are trying to run the correct file name.
- File and directory names are case sensitive.
How to change directories
To change directories, use the cd command in your terminal. For example, if your username was Me on the computer:
How to see what directory you are in
To check what directory you are currently in, use the folowing in your terminal.
How to print the contents of current directory
To see what files and directories exist in your current directory use the following in your terminal:
Conclusion
After reading this you should have some idea why you get the error Error: Cannot find module and how to diagnose and fix the problem.
Источник
Error: Cannot find module commands #349
Comments
crimson-med commented May 23, 2020 •
Report a bug?
What is the current behavior?
Published some updates on my package on npm and it is full broken.
Steps to reproduce:
- yarn global add vestigo
- vestigo scan —target=»https://127.0.0.1/» —method=»GET» -w
This does not happen with prior versions:
- yarn global add vestigo@0.0.5
- vestigo scan —target=»https://127.0.0.1/» —method=»GET»
This does not happen while debugging:
What is the expected behavior?
The command line is supposed to run like in prior versions
The text was updated successfully, but these errors were encountered:
crimson-med commented Jun 15, 2020
Any ideas on what could be causing this issue?
RasPhilCo commented Jul 3, 2020
Try installing with npm globally, yarn globally sometimes gets wonky.
martinlarosa commented Oct 28, 2020
Same thing is happening to me, it was working fine and then newer versions stopped working with that error.
I’m not using yarn.
martinlarosa commented Oct 28, 2020
It’s not generating any output into the lib directory. I have 3 commands, referencing other files under src/ and under another directory inside src/
Then I modify the file of one of the commands (just removing a line break), do npm pack and that file gets to the lib directory and into the packagle.
But then I run npm pack again withouit modifying any file and the lib is empty again
martinlarosa commented Oct 28, 2020
Weird thing is that the readme.md file and the help result is updated correctly
crimson-med commented Oct 28, 2020
Never been able to solve it personally I just have to run in dev mode. This really hinders my project so I’m thinking to find an alternative
martinlarosa commented Oct 28, 2020
Found the problem @crimson-med !
There’s a file in my directory called tsconfig.tsbuildinfo, that keeps a signature of the files. Clearly if the file didn’t change then it doesn’t compile it again.I don’t know when or why that file appeared there, but deleting the file fixes the problem.
The issue is that it appears again after packaging it again. So what I did was to add the removal of that file to the postpack script. Maybe it should go into the prepack? I’m not sure but this works for now.
Now my postpack looks like this : «postpack»: «rm -f oclif.manifest.json tsconfig.tsbuildinfo»,
crimson-med commented Nov 1, 2020
I tried that but it makes no difference for me @martinlarosa
dmoosocool commented Dec 24, 2020
@martinlarosa hi, thanks your idea. but this doesn’t seem to work for me.
«postpack»: «rm -f oclif.manifest.json tsconfig.tsbuildinfo»,
my package.json scripts:
this is yarn publish log,
The log shows its execution order
- run version script.
- run prepack script.
- run postpack script.
when executing yarn publish , the tsconfig.tsbuildinfo file may not be deleted when the prepack command was triggered.
so I try to delete the tsconfig.tsbuildinfo file in the prepack command.
here is updated package.json scripts:
its works for me..
@crimson-med If you are in the same situation as me, you can also try.
Источник
Когда я запускаю sails -v, sails lift или даже устанавливаю npm, я получаю эту ошибку. Пожалуйста, помогите —
Error: Cannot find module 'commander'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/usr/local/lib/node_modules/sails/bin/_commander.js:6:15)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
5 ответов
Лучший ответ
Удаление парусов и переустановка с помощью 'sudo'
решили эту проблему.
npm uninstall sails -g
sudo npm install sails -g
3
Don
22 Мар 2018 в 07:20
Установите commander
глобально.
sudo npm install commander -g
- Это установит командирский модуль в
/usr/lib/node_modules/
.
0
ahmnouira
23 Авг 2019 в 16:06
Когда я пытаюсь настроить новое приложение с помощью экспресс-генератора. ошибка: не удается найти модуль ‘commander’
Node version:12.16.1
switch node version :10.16.3
После того, как версия узла коммутатора работает нормально ..
0
Harendra Singh
12 Мар 2020 в 19:21
В моем случае это было из-за плохой версии узла. Я пробовал узел 8.15.1, и он работает.
0
Iiskaandar
31 Июл 2019 в 14:49
Скорее всего, commander
отсутствует в package.json
. Установите его и добавьте в package.json
, выполнив:
npm install commander --save
7
ralphtheninja
20 Мар 2018 в 21:47
When you are working in Node, you will sometimes encounter the error Cannot find module 'module-name'
with the error code MODULE_NOT_FOUND
.
The error looks like this:
internal/modules/cjs/loader.js:796
throw err;
^
Error: Cannot find module 'module'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
at Function.Module._load (internal/modules/cjs/loader.js:686:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_main_module.js:17:11 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
In this post, we’ll learn how to resolve this error.
What is the problem?
The issue is that Node is unable to find the module that you are trying to import into your Node application.
The most common reason for this is that you simply haven’t installed the project’s dependencies yet.
The project’s dependencies are listed in the package.json
file at the root of the project.
The Solution
To fix the Cannot find module
error, simply install the missing modules using npm
.
To so, you can use the following command:
npm install
If you are using the yarn
package manager, you can use the following command:
yarn install
This will install the project’s dependencies into your project so that you can use them.
Sometimes, this might still not resolve it for you. In this case, you’ll want to just delete your node_modules
folder and lock file (package-lock.json
or yarn.lock
) and try again.
This is how you can delete the node_modules
folder and lock files:
rm -rf node_modules
rm package-lock.json
rm yarn.lock
Local files
If your module is not coming from a remote source, you are seeing the error because the path to the local file is not correct.
Try to confirm that the path pointing to the local module is correct and your error should be resolved.
Conclusion
The Cannot find module
error is a common error that usually happens when dependencies are not installed. Once you install your dependencies and ensure that the paths are correct, you can resolve the error and run your application successfully.
Hopefully, this resolved the issue for you.
Thanks for reading!
If you want to learn about web development, founding a start-up, bootstrapping a SaaS, and more, follow me on Twitter! You can also join the conversation over at our official Discord!
-
Support Us
-
Join
-
Share
-
Tweet
-
Share
Give feedback on this page!