【问题标题】:Angular 4 - I keep getting Cannot find module 'portfinder' even after installing portfinder manuallyAngular 4 - 即使在手动安装 portfinder 后,我仍然无法找到模块“portfinder”
【发布时间】:2017-05-10 07:04:28
【问题描述】:

我在终端中使用 ng serve 在终端中不断收到此错误,我已经尝试过 ='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)

【问题讨论】:

    标签: javascript node.js angular angular-cli


    【解决方案1】:

    您需要 node v4.x 才能使其工作,另一种选择是转到 angular-cli 文件夹并使用 npm install portfinder 在那里安装 portfinder。如果本地 npm install portfinder 无法解决问题,则 portfinder 的全局安装应该可以工作。

    【讨论】:

    • 转到 angular-cli 文件夹并使用 npm install portfinder 安装 portfinder。
    【解决方案2】:

    好的,我解决了问题,问题是我的计算机上的双节点,(这就是为什么即使在安装 portfinder 后,我仍然找不到模块'portfinder')基本上如果你通过向导和自制软件安装节点,它们就会安装默认情况下在不同的地方,所以我做了什么,我通过这种方式删除了我的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
    

    这样所有包含 node 的文件夹都会被清除,所以我通过 homebrew 安装 node 并安装 yarn、angular cli、react-native cli 等...

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

    【讨论】:

      猜你喜欢
      • 2017-09-17
      • 2020-06-22
      • 1970-01-01
      • 2019-06-07
      • 2013-11-09
      • 1970-01-01
      • 1970-01-01
      • 2019-07-27
      • 1970-01-01
      相关资源
      最近更新 更多