[英]NodeJS: 'MODULE_NOT_FOUND' after installing package
这是我想作为 NodeJS 脚本运行的简单代码:
const fs = require('fs');
const { Test } = require('artillery');
const options = {
'key': fs.readFileSync('./key.pem'),
cert: fs.readFileSync('./certificates.pem'),
ca: fs.readFileSync('./ca.pem')
};
const test = new Test(config, options);
test.run((err, results) => {
if (err) {
console.error(err);
} else {
console.log(results);
}
});
当我运行它时:
node myscript.js
我收到错误错误: Cannot find module 'CL\path\to\node_modules\artillery\lib'. Please verify that the package.json has a valid "main" entry
Cannot find module 'CL\path\to\node_modules\artillery\lib'. Please verify that the package.json has a valid "main" entry
。
我尝试删除 node_modules 和 package_locks.json,然后使用npm install
重新安装 package.json 中的所有内容。 我也删除了npm缓存,删除了然后重新安装了Artillery package。nmp,nodejs和Artillery都是最新版本。
我的 package.json 是:
{
"name": "helloworld",
"version": "0.0.0",
"private": true,
"main": "./bin/www"
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"artillery": "^2.0.0-27",
"artillery-plugin-http-ssl-auth": "^0.0.1",
"axios": "^1.2.2",
"cookie-parser": "~1.4.4",
"date-fns": "^2.29.3",
"debug": "^4.3.4",
"express": "^4.18.2",
"http-errors": "~1.6.3",
"https": "^1.0.0",
"jshint": "^2.13.6",
"morgan": "^1.3.2",
"pug": "^2.0.4"
},
"devDependencies": {
"@types/artillery": "^1.7.0"
}
}
先感谢您!!
如错误所述,您缺少package.json
中的main
条目。 您可以使用./bin/www
:
"main": "./bin/www"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.