Himasha Harinda
Himasha Harinda

Reputation: 81

Cannot bootstrap an Express project using the express-generator tool

I've installed Node.js, express.js and the express-generator globally.
But when I try to create a new project using the express at the CLI, I get this error:

    module.js:471
        throw err;
        ^

    Error: Cannot find module 'commander'
        at Function.Module._resolveFilename (module.js:469:15)
        at Function.Module._load (module.js:417:25)
        at Module.require (module.js:497:17)
        at require (internal/module.js:20:19)
        at Object.<anonymous> (/usr/lib/nodejs/express-generator/bin/express:3:15)
        at Module._compile (module.js:570:32)
        at Object.Module._extensions..js (module.js:579:10)
        at Module.load (module.js:487:32)
        at tryModuleLoad (module.js:446:12)
        at Function.Module._load (module.js:438:

Error message advises to "re-install express-generator with sudo",
even if I haven't changed the node_modules variable path or anything else.

I haven't yet found a working solution. Please help me out on this

Upvotes: 3

Views: 807

Answers (3)

chrisb
chrisb

Reputation: 1

I had the same issue and was able to resolve it by uninstalling both packages. Don't forget to remove the from the whole system:

sudo npm uninstall -g express
sudo npm uninstall -g express-generator

After this I reinstalled both packages using

sudo npm install -g express express-generator 

In case of error code EEXISTS it's possible that files like a symlink to '/usr/bin/express' were not removed. Those files can be overwriten using --force.

Upvotes: 0

MwamiTovi
MwamiTovi

Reputation: 2502

This error originates from how you installed the express-generator tool.

Either

  • First run, npm uninstall -g express.
    Note that express-generator tool is to bootstrap express@4 projects.
    Thus, you are advised to first uninstall express globally since it only generates express@2 & @3 projects.
    This helps avoid conflicts.
  • Then run, npm install express -g express-generator.
  • For details, see official docs on migrating to express@4

Based on your question, the above two steps should resolve the issues.

Or

In case the errors persist, then consider installing the latest express-generator tool.

For my case, i had [email protected] but got the mentioned errors.

// Env: Windows-10, Node-v10.16.3, npm-v6.11.2

C:\>npm list -g --depth=0
  C:\Users\...\npm
  +-- [email protected]
  // other packages

Therefor, i reinstalled the tool...

C:\>npm install -g express-generator
C:\Users\...\npm\express -> C:\Users\...\npm\node_modules\express-generator\bin\express-cli.js
+ [email protected]
added 7 packages from 6 contributors, removed 1 package and updated 3 packages in 19.032s

// This command should run, if all went well
C:\>express --version
4.16.1

Upvotes: 0

ben fadhel Ichraf
ben fadhel Ichraf

Reputation: 151

I had the same issue as you and this how I fixed I uninstalled express generator then I updated npm and resinstalled express generator ,I re-arrange my path with this command PATH=~/npm/bin:$PATH and it works

Upvotes: 1

Related Questions