gpt4 book ai didi

javascript - node.js 本地模块 :cannot find module error

转载 作者:搜寻专家 更新时间:2023-10-31 23:26:16 24 4
gpt4 key购买 nike

我正在尝试在我的应用程序中实现本地模块

1.项目根文件夹我创建了名为 test 的文件夹,其中包含一个名为 index.js

的文件
      module.exports  = {

myFunction:function(){
console.log('ok');
}
}

2.在根文件夹的package.json中添加如下内容

"dependencies": { 
"test-module": "file:test"
}

3.当我尝试在 app.js 中导入 var module = require('test-module'); 时出现此错误

Cannot find module 'test-module'

最佳答案

you can provide a path to a local directory that contains a package

{
"name": "baz",
"dependencies": {
"bar": "file:../foo/bar"
}
}

并执行 npm install -snpm install --save reference

关于javascript - node.js 本地模块 :cannot find module error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48988958/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com