Angular-cli: Error: Cannot find module 'portfinder' with Webpack release and NPM 2

Created on 20 Aug 2016  路  7Comments  路  Source: angular/angular-cli

  1. OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)

Windows 7

  1. Versions. Please run ng --version. If there's nothing outputted, please run
    in a Terminal: node --version and paste the result here:

angular-cli: 1.0.0-beta.11-webpack.2
node: 6.2.2
npm: 2.15.6

  1. Repro steps. Was this an app that wasn't created using the CLI? What change did you
    do on your code? etc.

npm i -g [email protected]
ng

  1. The log given by the failure. Normally this include a stack trace and some
    more information.
Error while running script "C:\Program Files (x86)\nodejs\node_modules\angular-cli\addon\ng2\commands\serve.ts":
Error: Cannot find module 'portfinder'
    at Function.Module._resolveFilename (module.js:440:15)
    at Function.Module._load (module.js:388:25)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Program Files (x86)\nodejs\node_modules\angular-cli\addon\ng2\commands\serve.ts:6:18)
    at Module._compile (module.js:541:32)
    at Object.require.extensions..ts (C:\Program Files (x86)\nodejs\node_modules\angular-cli\lib\cli\index.js:29:14)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Class.module.exports.includedCommands (C:\Program Files (x86)\nodejs\node_modules\angular-cli\addon\ng2\index.js:16:16)
    at C:\Program Files (x86)\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 (x86)\nodejs\node_modules\angular-cli\node_modules\angular-cli\lib\models\project.js:391:15)
    at Project.eachAddonCommand (C:\Program Files (x86)\nodejs\node_modules\angular-cli\node_modules\angular-cli\lib\models\project.js:426:30)
    at module.exports (C:\Program Files (x86)\nodejs\node_modules\angular-cli\node_modules\angular-cli\lib\cli\lookup-command.js:33:13)
    at CLI.<anonymous> (C:\Program Files (x86)\nodejs\node_modules\angular-cli\node_modules\angular-cli\lib\cli\cli.js:34:26)
    at lib$rsvp$$internal$$tryCatch (C:\Program Files (x86)\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 (x86)\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 (x86)\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:440:15)
    at Function.Module._load (module.js:388:25)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Program Files (x86)\nodejs\node_modules\angular-cli\addon\ng2\commands\serve.ts:6:18)
    at Module._compile (module.js:541:32)
    at Object.require.extensions..ts (C:\Program Files (x86)\nodejs\node_modules\angular-cli\lib\cli\index.js:29:14)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Class.module.exports.includedCommands (C:\Program Files (x86)\nodejs\node_modules\angular-cli\addon\ng2\index.js:16:16)
    at C:\Program Files (x86)\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 (x86)\nodejs\node_modules\angular-cli\node_modules\angular-cli\lib\models\project.js:391:15)
    at Project.eachAddonCommand (C:\Program Files (x86)\nodejs\node_modules\angular-cli\node_modules\angular-cli\lib\models\project.js:426:30)
    at module.exports (C:\Program Files (x86)\nodejs\node_modules\angular-cli\node_modules\angular-cli\lib\cli\lookup-command.js:33:13)
    at CLI.<anonymous> (C:\Program Files (x86)\nodejs\node_modules\angular-cli\node_modules\angular-cli\lib\cli\cli.js:34:26)
    at lib$rsvp$$internal$$tryCatch (C:\Program Files (x86)\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 (x86)\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 (x86)\nodejs\node_modules\angular-cli\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1019:11)
  1. Mention any other details that might be useful.

The problem occurs with Webpack release and NPM 2. ember-cli depends on portfinder package and has it in node_modules after installation, but angular-cli expects portfinder to be located in its node_modules .
The problem can be solved by installing portfinder package manually in angular-cli or parent node_modules directory.

Most helpful comment

I had the same issue and needed to update npm.
npm install -g npm@latest

All 7 comments

I had the same issue and needed to update npm.
npm install -g npm@latest

@cmjacques It upgrades NPM to 3. The issue applies to NPM 2.x which may be used on purpose.

NPM3 is needed, yes. https://github.com/angular/angular-cli/pull/1748 adds that requirement to the README.

@filipesilva But it works flawlessly with NPM 2 in other respects. Relying on portfinder in root node_modules while it is a dependency of child dependency (ember-cli) looks like a bug to me, which is concealed by NPM 3 directory structure.

Forcing NPM 3 for globally installed packages is the last thing the one may want, because it turns global node_modules into a big mess, it is impossible to say which packages were originally installed with -g.

I'm sorry but there is just no way around NPM3. It's a hard dependency, and it has nothing to do with ember-cli actually. You can always use npm list -g --depth=0 to see your global package list.

+1

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings