Cordova cannot find module
Asked Answered
S

6

1

I allready searched for solutions but couldn't find anything that works.

I'm trying to build / run apk with cordova but the emulator (and also my phone) won't start the app and fail on installation. I tried to re-create the projet and re-install cordova but have this issue :

Error: Cannot find module 'C:\Users\...\AppData\Roaming\npm\node_modules\cordova\bin\cordova'

I also tried to do :

npm cache clean

Nothing is working, can someone help me please ? Thank you !

Supercilious answered 14/6, 2016 at 8:38 Comment(3)
How did you install cordova? Did you installed it globally?Sanderlin
I installed it by using > npm install -g cordova And also tried > npm install -g cordova-lib But I keep having the same issueSupercilious
Please don't add your answer into the question; you make an answer by actually using the text box that says "Add an answer". Also, please do not put "resolved" into the title. The question is considered resolved when you accept or upvote an answer.Brietta
C
8

I encountered the similar situation, here is the error information:

module.js:471
    throw err;
    ^

Error: Cannot find module 'C:\Users\MYUSERNAME\AppData\Roaming\npm\node_modules\cordova\bin\cordova'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:504:3

It happened after I upgraded my cordova with the command:

npm install cordova -g

Even when I ran the "cordova" command solely, same error I could get.

Finally solved by reinstall the cordova completely :

npm uninstall cordova -g

then

npm install cordova -g
Conglomerate answered 26/11, 2017 at 16:7 Comment(0)
M
5

In my case solved by removing and adding platform android again

cordova platform rm android
cordova platform add android
Misspell answered 17/7, 2020 at 20:27 Comment(0)
D
2

I know, this question is kinda old but I got the same problem and I "by-pass" it with this method.

(SOLVED) Error: Cannot find module 'C:...\node_modules\cordova\bin\cordova' #3301

Actually, using ionic (Ionic CLI) : 3.20.0

first of all, check the JRE installation on your computer, if is ok, follow this steps

  1. ionic serve
  2. cordova clean android (or IOS)
  3. rm -rf node_modules (just delete node_modules folder)
  4. npm install
  5. cordova build android (without ionic)

It will add plugins to your project and also will compile it to an APK.

EDIT:

Just create another project, copy the "src" folder to the new one and ready to go!

Dysphoria answered 14/8, 2018 at 2:29 Comment(0)
M
1

You just need to run these commands

npm uninstall -g cordova
npm install -g cordova@latest

Above commands are already answered but removing android and adding it again is important and then these :

cordova platform rm android/ios/browser
cordova platform add android/ios/browser

Worked for me, hope it help others.

Minimus answered 11/10, 2021 at 19:41 Comment(0)
F
0

Follow these Steps:

npm uninstall -g cordova
npm install -g cordova@latest
Finical answered 14/8, 2018 at 4:44 Comment(0)
B
0

ss image

i tried :

npm uninstall -g cordova  

npm install -g cordova@latest

but, everytime i run cordova

module.js:471
throw err;
^ Error: Cannot find module 'C:\Users\MYUSERNAME\AppData\Roaming\npm\node_modules\cordova\bin\cordova'

im install manualy, open : C:\Users\MYUSERNAME\AppData\Roaming\npm\node_modules\ and create folder : cordova\bin

then i run

yarn add cordova

this solve, my problem

Brout answered 2/5, 2023 at 14:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.