安装了brew的全局模块程序包节点无法找到模块
问题描述:
在OSX EI Capitan 10.11.2下,使用brew安装的全局模块程序包(npm -g install [程序包名称])节点无法找到模块。我的代码如下安装了brew的全局模块程序包节点无法找到模块
"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'”,我尝试将〜/ .bashrc和〜/ .bash_profile写入“NODE_PATH =”/ usr/local/lib/node_modules /“它不起作用。我知道使用安装的全局第三个模块应该用绝对路径调用,或者直接使用基于当前文件夹安装的第三个模块,但是我想根据“require('package'name')使用第三个模块。 “直接。我该怎么办,谁能帮助我?
答
我在MacOS上安装了如此多的node
问题,我决定搬到nvm
,所有关于rights/locations/global/...的问题都消失了,节省了我的时间。
在顶端你得到一个版本管理其结束的时候,你的项目之间切换是很有益的节点