angular4 – 我继续得到即使手动安装portfinder也找不到模块“portfinder”

我不断收到这个错误在我的terminal使用ng服务terminal,我已经尝试='npm install portfinder ,也是npm uninstall -g angular-cli, npm cache clean, npm install npm -g, npm install -g angular-cli ,但没有工作,我一直得到它,我使用npm 3.10.10,Angular4和错误如下:

 Cannot find module 'portfinder' Error: Cannot find module 'portfinder' 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/local/lib/node_modules/angular-cli/commands/serve.js:6:18) 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:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Class.includedCommands (/usr/local/lib/node_modules/angular-cli/addon/index.js:21:16) at /usr/local/lib/node_modules/angular-cli/node_modules/angular-cli/lib/models/project.js:392:61 at Array.forEach (native) at Project.addonCommands (/usr/local/lib/node_modules/angular-cli/node_modules/angular-cli/lib/models/project.js:391:15) at Project.eachAddonCommand (/usr/local/lib/node_modules/angular-cli/node_modules/angular-cli/lib/models/project.js:426:30) at module.exports (/usr/local/lib/node_modules/angular-cli/node_modules/angular-cli/lib/cli/lookup-command.js:33:13) at CLI.<anonymous> (/usr/local/lib/node_modules/angular-cli/node_modules/angular-cli/lib/cli/cli.js:34:26) at tryCatch (/usr/local/lib/node_modules/angular-cli/node_modules/angular-cli/node_modules/rsvp/dist/lib/rsvp/-internal.js:215:12) at invokeCallback (/usr/local/lib/node_modules/angular-cli/node_modules/angular-cli/node_modules/rsvp/dist/lib/rsvp/-internal.js:230:13) at publish (/usr/local/lib/node_modules/angular-cli/node_modules/angular-cli/node_modules/rsvp/dist/lib/rsvp/-internal.js:198:7) at flush (/usr/local/lib/node_modules/angular-cli/node_modules/angular-cli/node_modules/rsvp/dist/lib/rsvp/asap.js:82:5) at _combinedTickCallback (internal/process/next_tick.js:73:7) at process._tickCallback (internal/process/next_tick.js:104:9) 

你需要节点v4.x才能正常工作,另一种方法是使用npm install portfinder安装port-cli文件夹并npm install portfinder 。 如果本地的npm安装portfinder无法解决这个问题,一个全球安装的portfinder应该工作。

好的,我解决了这个问题,问题是我的电脑上双节点(这就是为什么即使安装portfinder之后,我仍然无法find模块'portfinder')基本上,如果你通过向导和homebrew安装节点,它们被安装在不同的地方默认情况下,我做了什么,我通过这种方式删除我的Mac中的任何节点文件夹,我发现:

 # first: lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.* # To recap, the best way (I've found) to completely uninstall node + npm is to do the following: # go to /usr/local/lib and delete any node and node_modules cd /usr/local/lib sudo rm -rf node* # go to /usr/local/include and delete any node and node_modules directory cd /usr/local/include sudo rm -rf node* # if you installed with brew install node, then run brew uninstall node in your terminal brew uninstall node # check your Home directory for any "local" or "lib" or "include" folders, and delete any "node" or "node_modules" from there # go to /usr/local/bin and delete any node executable cd /usr/local/bin sudo rm -rf /usr/local/bin/npm sudo rm -rf /usr/local/bin/node ls -las # you may need to do the additional instructions as well: sudo rm -rf /usr/local/share/man/man1/node.1 sudo rm -rf /usr/local/lib/dtrace/node.d sudo rm -rf ~/.npm 

这样,包含节点的所有文件夹都被清除了,所以我通过自制软件安装节点并安装纱线,angular度cli,反应原生cli等。

我想分享这个,希望帮助其他同样的问题的人。