Error: Cannot find module 'js-yaml' when running "bower install"
Asked Answered
T

2

5

I am walking through basic set up of an AngularJS application (Just getting started) and am currently trying to install Bower components for the application.

When I run bower install from the terminal, I get the following error:

Error: Cannot find module 'js-yaml'
    at Function.Module._resolveFilename (module.js:337:15)
    at Function.Module._load (module.js:287:25)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (Path\bower\node_modules\configstore\index.js:9:12)
    at Module._compile (module.js:425:26)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)

I haven’t specified js-yaml module anywhere in my scripts (as far as I am aware), so not sure where this dependency is coming from.

I have tried deleting the node_modules folder, clearing the npm cache, including js-yaml within the package.json file then re-running npm install, but I get the same error when running bower install

If it helps, my bower.json and package.json files are shown below:

Bower.json

{
  "name": "starter-node-angular",
  "version": "1.0.0",
  "dependencies": {
    "bootstrap": "latest",
    "font-awesome": "latest",
    "animate.css": "latest",
    "angular": "latest",
    "angular-route": "latest"
  }
}

package.json

{
  "name": "starter-node-angular",
  "main": "server.js",
  "dependencies": {
    "express" : "~4.5.1",
    "mongoose" : "~3.8.0",
    "body-parser" : "~1.4.2",
    "method-override" : "~2.0.2",
    "js-yaml" : "latest"
  }
}

I am using WebStorm 10.0.4 (empty project as the starting point).

Has anyone come across this or a similar issue and possible point me in the right direction on how to resolve the issue?

Tyche answered 25/11, 2015 at 23:34 Comment(3)
Modify the package.json file to look like this and then do npm install. When that finish, then do bower installEnate
Hi Lucio, Thanks for the feedback. I will try out the solutions offered later today. In the meantime, could you explain what "js-yaml" : "latest" is doing versus "js-yaml" : "*" ? Just what to understand the difference.Tyche
I couldn't see anywhere on the npm documentation to use latest to get the latest version of a package, the * is used for that. Doing so might install the package hence solving your problem.Enate
C
6

Running sudo npm install -g js-yaml first should get you in the right direction.

Crossopterygian answered 26/11, 2015 at 2:12 Comment(2)
This answer clicked it for me. I just closed Webstorm and run it again as admin. Worked fine post doing this.Tyche
note that along with running webstorm as Admin, I also included --save in the npm command to save the dependency to the package.json file.Tyche
M
3

My guess is that its not related to your application but bower is broken. Try reinstall it:

$ npm uninstall bower

And then reinstall it like this:

$ npm install -g bower

That solved it for me.

Matheny answered 26/11, 2015 at 0:42 Comment(1)
appears this error after install bower: npm ERR! code 1Marquez

© 2022 - 2024 — McMap. All rights reserved.