Stav Alfi
Stav Alfi

Reputation: 13923

Cannot find module 'glob'

Tell me what extra information you need

Im following a simple guide to activate my first angular 2 app and did the following actions on the clr:

npm i -g angular-cli    //(worked)

ng new ponyracer        //(error: Cannot find module 'glob')
ng serve                //(error: Cannot find module 'glob')

Cannot find module 'glob'
Error: Cannot find module 'glob'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (C:\Users\stavalfi\AppData\Roaming\npm\node_modules\angular-cli\addon\ng2\tasks\lib-install.js:11:19)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)

Any explations about the commands "ng new ponyracer" and "ng serve" will be great.

Thanks, Stav

Upvotes: 29

Views: 60677

Answers (5)

Hossien Salamhe
Hossien Salamhe

Reputation: 121

  1. remove node_modules
  2. remove package-lock.json
  3. npm i
  4. npm run ...

Upvotes: 1

pramod-dev
pramod-dev

Reputation: 1

I had the same issue.

Cannot find module 'module_name'

Error: Cannot find module 'module_name'

When I run the command:

npm install --save module_name

Note: Here the 'module_name' is the name of the missing module. example: fs-extra, glob, dependency-graph, sort-package-json, @phosphor/coreutils, prettier etc.

It throws a new error that a new module is missing. And it kept happening everytime I try to fix an error, a new error pops up the next time(other packages mentioned above).

Here's what I did to solve the error:

I had to uninstall and unlink nodejs and npm : Note: use unlink only if you have linked them before, otherwise, it's not necessary

brew uninstall node

brew unlink node

brew unlink npm

brew unlink node_modules

Make sure you remove all the node_modules, npm and nodejs folders from your system. My commands below can be different from yours. You can manually search for folders and remove them as well:

rm -rf /usr/local/lib/node_modules

sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}

sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp

After uninstalling and deleting all node, npm folders, I ran these commands:

brew install node

npm install yarn -g

npm install -g typescript

npm install

yarn install

That fixed all the issues

Upvotes: 0

Eric Martinez
Eric Martinez

Reputation: 31777

There's already an issue reporting this error message. The workaround until the next release is to install glob for the project (npm install --save glob)

Regarding the commands, according to their repository under Generating and serving an Angular2 project via a development server the commands are as follow

ng new ponyracer : This command will create a project named ponyracer (a folder named ponyracer with all the set up in it).

ng serve : This command will run the live reload server to serve the application so you can see it in your browser.

PS : If you test the solution suggested in the issue it would be nice of you to report if it worked or not.

PS2 : I tested now (I fixed my error) and I cannot reproduce your error. I'm using node v5.5.0 and npm v3.7.3. Can you specify which node and npm versions are you using?

Upvotes: 38

Jason Awbrey
Jason Awbrey

Reputation: 919

For now, run npm install --save glob in your project, or install globally npm install -g glob like Eric mentioned.

This is listed in Issue #233 on the angluar-cli project.

The missing glob dep has been fixed in latest master. This will go out in the next release. - posted 4/21/16

Versions ran with this fix:

  • angular-cli: 0.0.33
  • node: 5.9.1
  • glob: 7.0.3
  • angular2: 2.0.0-beta.14

Upvotes: 2

user3591410
user3591410

Reputation: 21

I had the same error on Windows 10,

D:\Code\AngularJS>ng new greetings-ac
Cannot find module 'glob'
Error: Cannot find module 'glob'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (D:\Code\node_modules\angular-cli\addon\ng2\tasks\lib-install.js:11:19)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)

but the following fixed it:

D:\Code\AngularJS>npm install -g angcli

D:\Code\AngularJS>ng new greetings-ac
? Select project blueprint: Default template
Cloning into 'D:\Code\AngularJS\greetings-ac'...
install installing using npm
npm WARN package.json [email protected] No description
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No README data
npm WARN deprecated [email protected]: This package has been discontinued in favor of lodash@^4.0.0.
npm WARN optional dep failed, continuing [email protected]
npm WARN deprecated [email protected]: This package has been discontinued in favor of lodash@^4.0.0.
npm WARN optional dep failed, continuing [email protected]

Upvotes: 2

Related Questions