angular-cli: Error: Cannot find module 'portfinder' when doing any ng commands

I am currently using Windows 10 on this device, same as my laptop which doesn’t seem to be having issues with the cli. I also have npm version 3.10.6 and nodejs version 6.4.0. I am running the command prompt in Administrator mode if that’s makes a difference.

Regrettably like stated in the title I cannot run any angular-cli commands without the error, including “–version”, but I did install angular-cli@webpack with npm. I also haven’t started creating an app yet on this device due to this error.

Log from command prompt: (same error on everything command)

$ ng --version
(node:11820) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
Error while running script "C:\Program Files\nodejs\node_modules\angular-cli\addon\ng2\commands\serve.ts":
Error: Cannot find module 'portfinder'
    at Function.Module._resolveFilename (module.js:455:15)
    at Function.Module._load (module.js:403:25)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Program Files\nodejs\node_modules\angular-cli\addon\ng2\commands\serve.ts:6:18)
    at Module._compile (module.js:556:32)
    at Object.require.extensions..ts (C:\Program Files\nodejs\node_modules\angular-cli\lib\cli\index.js:29:14)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Class.module.exports.includedCommands (C:\Program Files\nodejs\node_modules\angular-cli\addon\ng2\index.js:16:16)
    at C:\Program Files\nodejs\node_modules\angular-cli\node_modules\angular-cli\lib\models\project.js:392:61
    at Array.forEach (native)
    at Project.addonCommands (C:\Program Files\nodejs\node_modules\angular-cli\node_modules\angular-cli\lib\models\project.js:391:15)
    at Project.eachAddonCommand (C:\Program Files\nodejs\node_modules\angular-cli\node_modules\angular-cli\lib\models\project.js:426:30)
    at module.exports (C:\Program Files\nodejs\node_modules\angular-cli\node_modules\angular-cli\lib\cli\lookup-command.js:33:13)
    at CLI.<anonymous> (C:\Program Files\nodejs\node_modules\angular-cli\node_modules\angular-cli\lib\cli\cli.js:34:26)
    at lib$rsvp$$internal$$tryCatch (C:\Program Files\nodejs\node_modules\angular-cli\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1036:16)
    at lib$rsvp$$internal$$invokeCallback (C:\Program Files\nodejs\node_modules\angular-cli\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1048:17)
    at lib$rsvp$$internal$$publish (C:\Program Files\nodejs\node_modules\angular-cli\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1019:11)
Cannot find module 'portfinder'
Error: Cannot find module 'portfinder'
    at Function.Module._resolveFilename (module.js:455:15)
    at Function.Module._load (module.js:403:25)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Program Files\nodejs\node_modules\angular-cli\addon\ng2\commands\serve.ts:6:18)
    at Module._compile (module.js:556:32)
    at Object.require.extensions..ts (C:\Program Files\nodejs\node_modules\angular-cli\lib\cli\index.js:29:14)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Class.module.exports.includedCommands (C:\Program Files\nodejs\node_modules\angular-cli\addon\ng2\index.js:16:16)
    at C:\Program Files\nodejs\node_modules\angular-cli\node_modules\angular-cli\lib\models\project.js:392:61
    at Array.forEach (native)
    at Project.addonCommands (C:\Program Files\nodejs\node_modules\angular-cli\node_modules\angular-cli\lib\models\project.js:391:15)
    at Project.eachAddonCommand (C:\Program Files\nodejs\node_modules\angular-cli\node_modules\angular-cli\lib\models\project.js:426:30)
    at module.exports (C:\Program Files\nodejs\node_modules\angular-cli\node_modules\angular-cli\lib\cli\lookup-command.js:33:13)
    at CLI.<anonymous> (C:\Program Files\nodejs\node_modules\angular-cli\node_modules\angular-cli\lib\cli\cli.js:34:26)
    at lib$rsvp$$internal$$tryCatch (C:\Program Files\nodejs\node_modules\angular-cli\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1036:16)
    at lib$rsvp$$internal$$invokeCallback (C:\Program Files\nodejs\node_modules\angular-cli\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1048:17)
    at lib$rsvp$$internal$$publish (C:\Program Files\nodejs\node_modules\angular-cli\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1019:11)

I have tried solutions from these: Angular2 : Need to create angular2 folder structure using latest angularCLI Webpack and Error: Cannot find module ‘portfinder’ with Webpack release and NPM 2 #1770 with no success and cannot seem to find anything else about this on google. Unlike the latter link, I do not care what version of npm I am using.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 6
  • Comments: 16 (1 by maintainers)

Most upvoted comments

If a local npm install portfinder fails to fix the issue, a global install of portfinder works.

Please install those dependence manually such as reflect-metadata and portfinder globally.

I got the same problem and I solved the issue for me by going to my angular-cli folder and installing portfinder there with npm install portfinder it’s working now but not sure why I got the error. My colleagues have a very similar setup (mac, node 6.5.0, npm 3.10.6) and they didn’t get this error.

I can reproduce this by wiping angular-cli or node modules and reinstalling