【问题标题】:global modules package node installed with brew Cannot find module使用brew安装的全局模块包节点找不到模块
【发布时间】:2016-06-08 12:49:05
【问题描述】:

在 OSX El Capitan 10.11.2 下,使用 brew 安装的全局模块包(npm -g install [包名])节点找不到模块。我的代码如下

"use strict";
require('es6-shim');
const fs = require('fs');
let promise = fs.readFile("example.txt");

promise.then(function(contents) {
    // fulfillment
    console.log(contents);
}, function(err) {
    // rejection
    console.error(err.message);
});

promise.then(function(contents) {
    // fulfillment
    console.log(contents);
});

promise.then(null, function(err) {
    // rejection
    console.error(err.message);
});

运行上面的代码结果“找不到模块'es6-shim'”,我尝试将“NODE_PATH =“/usr/local/lib/node_modules/”写入〜/ .bashrc和〜/ .bash_profile,但它没有'不起作用。我知道使用安装的第三个模块全局应该使用绝对路径或直接使用基于当前文件夹安装的第三个模块,但我想根据“require('package's name')”直接使用第三个模块.

【问题讨论】:

    标签: node.js npm


    【解决方案1】:

    我在 MacOS 上安装 node 时遇到了很多问题,我决定迁移到 nvm,我所有关于权限/位置/全局/...的问题都解决了,节省了我的时间。

    最重要的是,您可以获得节点的版本管理,当您在项目之间切换时会非常有用

    【讨论】:

      猜你喜欢
      • 2014-11-04
      • 1970-01-01
      • 2018-03-08
      • 2019-01-09
      • 2012-09-17
      • 2017-08-11
      • 2017-07-15
      • 2016-05-08
      • 1970-01-01
      相关资源
      最近更新 更多