Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Cannot find module 'portfinder' when doing any ng commands #1782

Closed
zjkipping opened this issue Aug 20, 2016 · 16 comments
Closed

Error: Cannot find module 'portfinder' when doing any ng commands #1782

zjkipping opened this issue Aug 20, 2016 · 16 comments
Labels
needs: repro steps We cannot reproduce the issue with the information given

Comments

@zjkipping
Copy link

zjkipping commented Aug 20, 2016

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.

@filipesilva filipesilva added the needs: repro steps We cannot reproduce the issue with the information given label Aug 23, 2016
@filipesilva
Copy link
Contributor

I can't reproduce this on Windows 10 myself. It looks like your install is missing a package, which can be the result of a broken install or of a NPM upgrade without reinstall.

This should work if that's the case, but you say you've tried it already:

 npm uninstall -g angular-cli
 npm cache clean 
 npm install -g angular-cli@webpack

I'll leave the issue open in case there's a way to repro this I can use to debug.

@web-dave
Copy link

web-dave commented Aug 24, 2016

Same Problem here.
uninstall and install not solveing this.

If i run any ng command outside a cli Project it works fine.

$ ng v
angular-cli: 1.0.0-beta.11-webpack.2
node: 4.4.0
os: win32 x64

History:
I build a app with cli yesterday. Everything works fine.
Then I moved my files into a Project to push all to git.
clone this Project and run:
npm i
npm install --save-dev angular-cli@webpack
this throws error:

npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: [email protected]
npm WARN optional Skipping failed optional dependency /karma/chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: [email protected]
npm WARN @angular/[email protected] requires a peer of typescript@^1.9.0-dev but none was installed.
npm WARN [email protected] requires a peer of typescript@^1.8.0 || ^1.9.0-dev but none was installed.
npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\Program Files\nodejs\node.exe" "D:\Users\damu1de\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js" "install" "--save-dev" "angular-cli@webpack"
npm ERR! node v4.4.0
npm ERR! npm v3.8.7
npm ERR! path d:\workspace\DomainJumper\GUI\node_modules.staging\abbrev-7e384210
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall rename

npm ERR! enoent ENOENT: no such file or directory, rename 'd:\workspace\DomainJumper\GUI\node_modules.staging\abbrev-7e384210' -> 'd:\workspace\DomainJumper\GUI\node_modules\ember-cli\node_modules\npm\node_modules\abbrev'
npm ERR! enoent ENOENT: no such file or directory, rename 'd:\workspace\DomainJumper\GUI\node_modules.staging\abbrev-7e384210' -> 'd:\workspace\DomainJumper\GUI\node_modules\ember-cli\node_modules\npm\node_modules\abbrev'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! Please include the following file with any support request:
npm ERR! d:\workspace\DomainJumper\GUI\npm-debug.log

When i run:
ng serve

module.js:327
throw err;
^

Error: Cannot find module 'semver'
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. (d:\workspace\DomainJumper\GUI\node_modules\ember-cli\lib\utilities\platform-checker.js:3:14)
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)

hmmpf

package.json says:

"typescript": "^2.0.0"

Why????

I Change it to
"typescript": "^1.8.10".
Next try

ng version works now
ng serve throws error:

ERROR in ./src/main.ts
Module build failed: TypeError: this.ts.getAutomaticTypeDirectiveNames is not a function
at State.loadTypesFromConfig (d:\workspace\DomainJumper\GUI\node_modules\awesome-typescript-loader\src\host.ts:148:36)
at new State (d:\workspace\DomainJumper\GUI\node_modules\awesome-typescript-loader\src\host.ts:142:14)
at Object.ensureInstance (d:\workspace\DomainJumper\GUI\node_modules\awesome-typescript-loader\src\instance.ts:150:19)
at compiler (d:\workspace\DomainJumper\GUI\node_modules\awesome-typescript-loader\src\index.ts:37:20)
at Object.loader (d:\workspace\DomainJumper\GUI\node_modules\awesome-typescript-loader\src\index.ts:18:18)
@ multi main

ERROR in ./src/polyfills.ts
Module build failed: TypeError: this.ts.getAutomaticTypeDirectiveNames is not a function
at State.loadTypesFromConfig (d:\workspace\DomainJumper\GUI\node_modules\awesome-typescript-loader\src\host.ts:148:36)
at new State (d:\workspace\DomainJumper\GUI\node_modules\awesome-typescript-loader\src\host.ts:142:14)
at Object.ensureInstance (d:\workspace\DomainJumper\GUI\node_modules\awesome-typescript-loader\src\instance.ts:150:19)
at compiler (d:\workspace\DomainJumper\GUI\node_modules\awesome-typescript-loader\src\index.ts:37:20)
at Object.loader (d:\workspace\DomainJumper\GUI\node_modules\awesome-typescript-loader\src\index.ts:18:18)

run ng init
ng serve works. PUH! hard work.

@dcavanagh
Copy link

dcavanagh commented Aug 24, 2016

I am seeing the same or similar problem on mac. I have attached the npm debug file
npm-debug.txt

@web-dave
Copy link

I found (for me) followed solution:
Just short my last post.

clone project
npm i
npm install --save-dev angular-cli@webpack
ng init (no overwrite)

i find out that you need node v4.x to get it work, (had this problem with a team member)

regards

@zjkipping
Copy link
Author

zjkipping commented Aug 26, 2016

So I ended up taking a look at this again, since it would be preferable if I could get my desktop to run angular-cli vs my laptop.

I went ahead and uninstalled nodejs and wiped anything npm from appdata/roaming. Then installed the exact versions of Node.js (6.1.0) and npm (3.10.6) that my laptop has. Then attempting to install Angular-cli on the version of 1.0.0-beta.11-webpack.

I managed to watch the install closely this time and noticed some errors, that I haven't seen before on my laptop... Below are images of the errors

The first was an error then followed by a ton of warnings, that I have never noticed
error1
The second is a much larger error
error2

Still ending up with the same 'portfinder' error when I attempt ANY ng commands, such as just typing ng by itself and hitting enter, ng init, ng new test_prog, ng -v, etc...

@bbohling
Copy link

bbohling commented Aug 27, 2016

So I had this same issue during a project upgrade and resolved by going through a few hoops...

  1. First off I was using an LTS version of node (v4.x with npm v2.x) which resulted in the portfinder error
  2. I then tried to update to the latest LTS version, but still failed
  3. Succumbed to the fact that the pre-reqs are true I used nvm to install the latest node 6.x and npm 3.x
  4. I performed the uninstall and cache clean steps
  5. This time I got a different error: could not find module config-chain
  6. Following the instructions in Cannot find module 'exists-sync' #1186 I navigated to my local (project) instance of node_modules/angular-cli/ and ran npm install
  7. Ran ng init with no issues

@zjkipping
Copy link
Author

@bbohling Did something similar to what you suggested, as I don't even have a project created yet since I cannot run any commands. I went to where my angular-cli was installed globally, appdata/roaming/npm/node_modules, and ran npm install there. Unfortunately I still get the above npm install errors and the portfinder error outlined in the images of my previous comment...

@bbohling
Copy link

Sorry @zjkipping I should have explicitly stated that I navigated not to the global angular-cli instance, but my local (project) instance.

@retallicka
Copy link

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

@jodytate
Copy link

jodytate commented Sep 9, 2016

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

@zjkipping
Copy link
Author

zjkipping commented Sep 11, 2016

Thank @retallicka and @jodytate for the very helpful answers. This seems to have done the trick for me. I can now run ng perfectly fine outside of another older angular-cli webpack project. I believe this problem is just that I am now on a newer version of the cli (beta.11-webpack.8) vs when I created it in the early days of beta.11-webpack.2. I'll go ahead and close this since my issues have been resolved.

@foaudkajj
Copy link

foaudkajj commented Sep 18, 2016

Worked for me thanks 👍
cd your_project_folder
Then :
npm install --save-dev angular-cli@webpack
ng init

@mohammedzamakhan
Copy link

@retallicka @jodytate followed both steps, but doesn't works on my MAC

@damoqiongqiu
Copy link

@jodytate
npm install portfinder solved the problem on my MAC.

@rocky-bgta
Copy link

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

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs: repro steps We cannot reproduce the issue with the information given
Projects
None yet
Development

No branches or pull requests