Cordova cannot find module

天涯浪子 提交于 2019-12-11 05:58:18

问题


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 !


回答1:


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!




回答2:


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



回答3:


Follow these Steps:

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


来源:https://stackoverflow.com/questions/37806958/cordova-cannot-find-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!