nparashuram / cordova-plugin-browsersync

BrowserSync Plugin for Cordova
110 stars 69 forks source link

Installation to cordova project was fail. ("Error: Cannot find module 'npm'") #51

Closed jsakamoto closed 6 years ago

jsakamoto commented 6 years ago

Environment

After cordova create ..., and installed "browser" and "android" platforms.

What's happen?

When I execute the command as following,

> cordova plugin add cordova-plugin-browsersync

the command reported the error as follows.

Installing "cordova-plugin-browsersync" for browser
Failed to install 'cordova-plugin-browsersync': Error: Cannot find module 'npm'
    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 Context.requireCordovaModule (C:\Users\j-sakamoto\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\hooks\Context.js:77:12)
    at module.exports (D:\Projects\Studies\CordovaApp2\plugins\cordova-plugin-browsersync\lib\npmInstall.js:10:23)
    at runScriptViaModuleLoader (C:\Users\j-sakamoto\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\hooks\HooksRunner.js:188:18)
    at runScript (C:\Users\j-sakamoto\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\hooks\HooksRunner.js:164:16)
    at C:\Users\j-sakamoto\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\hooks\HooksRunner.js:132:20
    at _fulfilled (C:\Users\j-sakamoto\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:787:54)

Note

I was successes installing this plugin to the cordova project, which wasn't added "android" platform.


What can I do?

Is there any workarounds?

Thanks,

axemclion commented 6 years ago

Could you check your node_modules to see the npm modules that were installed ?

jsakamoto commented 6 years ago

Could you check your node_modules to see the npm modules that were installed ?

Yes, there is the npm module as ~/node_module/npm folder.

After I'm investigating this issue for few hours, I found a solution for me.

The version of npm which global installed in my pc was v.5.5.1.
But, the version of npm which project local installed by this plugin is v.5.6.0.

So I tried to solve this issue by upgrading the npm version of global installed as following command.

> npm install -g npm

After that, cordova plugin add cordova-plugin-browsersync works fine, even if android platform is added or not.

Will this information be useful to you or to those who encountered this problem?

axemclion commented 6 years ago

I think this is great info. Can you send a PR to the README to include this info ? I am sure it would help others .