下面是我想作为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
.
我试着删除node_modules和package_locks.json,然后用npm install
重新安装package.json中的所有内容。我还删除了npm缓存,删除并重新安装了Artillery包。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"
}
}
提前感谢你!!
1条答案
按热度按时间wkyowqbh1#
如错误所示,您的
package.json
中缺少一个main
条目,您可以使用./bin/www
: