【发布时间】:2017-10-05 22:56:04
【问题描述】:
我创建了一个节点模块,但似乎无法正确使用它。这是我的 index.js 用于所述模块:
const thing = require('./thing.js');
exports.thing = thing;
这里是thing.js:
module.exports = 'foobar';
这是 package.json:
{
"name": "thing-both",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
这是我想在其他模块中使用的 package.json:
{
"name": "another-thing",
"description": "",
"dependencies": {
"thing-both": "file:../both"
},
"private": true
}
我运行 npm install 并安装模块。当我尝试要求我在 anotherThing 模块中创建的模块时,我收到“找不到模块”错误。这是我的要求声明:
const thing = require('thing-both');
我注意到的一件事是安装的模块没有文件,并且文件夹在我的目录侧边栏中有一个图标(使用 Sublime 3,图标看起来像一个符号链接图标):
这是我正在使用的项目目录:
both
thing.js
index.js
package.json
other
// stuff
我在这里可能做错了什么?
【问题讨论】: