javascript - 找不到 NPM 本地安装的模块
问题描述
我正在开发一个工具,我已经通过 NPM 在本地安装了一些模块,当我尝试通过 NodeJS 要求这些模块时出现错误。我在 Windows 10 中工作,我已经尝试过设置 NODE_PATH 等。
以下是我的文件结构:
->project
---->node_modules
---->src
-------->css
-------->js
----------->index.js
---->package.json
---->index.html
我使用 index.js 等填充 index.html。下面是我的代码package.json
:
{
"name": "bip39",
"version": "1.0.0",
"description": "A tool for converting BIP39 mnemonic phrases to addresses and private keys.",
"directories": {
"test": "tests"
},
"dependencies": {
"bip39": "^2.6.0",
"bigi": "^1.4.2",
"create-hmac": "^1.1.7",
"nem-sdk": "^1.6.7"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/PavlosTze/bip39.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/PavlosTze/bip39/issues"
},
"homepage": "https://github.com/PavlosTze/bip39#readme"
}
下面是我的 require() 代码:
var createHmac = require("create-hmac");
var BigInteger = require("bigi");
const bip39 = require("bip39");
const nem = require("nem-sdk").default;
我在 NPM 上完成了以下步骤:
1) npm init
2) npm install bip39
3) npm install nem-sdk
4) npm install bigi
5) npm install create-hmac
所有这些文件都在里面node_modules
,但是,每当我在浏览器中运行代码时,我都会收到所有模块的“错误:找不到模块“bip39”等。
编辑:在我克隆了同一个工具的另一个目录上,在我将它与另一个工具合并之前,我没有收到任何错误,并且一切正常,包括 require()。等等。你还需要这些文件吗?
有人能帮助我吗?
解决方案
尝试这个 :
rm -rf node_modules
npm install