TypeError: Cannot read property 'match' of undefined on NodeJs
TypeError: Cannot read property 'match' of undefined on NodeJs
我不知道如何解决这个问题
- $
rm -rf package-lock.json node_modules <-- you need both
- $
npm install
- 插入稳定版本的节点 (10.16.0)
这是我的package.json
{
"name": "xxxx",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "supervisor -i node_modules index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.0",
"bot-brother": "^2.1.5",
"chalk": "^2.4.1",
"cors": "^2.8.4",
"date-fns": "^1.29.0",
"dotenv": "^4.0.0",
"express": "^4.15.4",
"helmet": "^3.8.1",
"joi": "^10.6.0",
"morgan": "^1.9.1",
"pg": "^7.6.1",
"raven": "^2.2.1",
"supervisor": "^0.12.0"
}
}
当我尝试 npm start
时收到此错误
我单独安装的唯一软件包是 supervisor(npm install supervisor),但只是因为脚本 npm start 需要它。
如果您需要其他文件,我很乐意 post :)
我不知道该怎么办,我该如何解决?
更新
根据要求,这是 bot.js
const bb = require('bot-brother');
const fs = require("fs");
const path = require('path');
const basename = path.basename(__filename);
const bot = bb({
key: process.env.BOT_KEY,
sessionManager: bb.sessionManager.redis({ port: process.env.REDIS_PORT, host: process.env.REDIS_HOST }),
polling: { interval: 5, timeout: 65 }
});
//middlewares
bot.use('before', bb.middlewares.typing());
const actions = {}
//load all actions wrappers
fs
.readdirSync(__dirname + "/actions")
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(file => {
const name = file.replace(".js", "")
actions[name] = require(path.join(__dirname + "/actions", file));
});
//load all actions
Object.keys(actions).forEach(name => actions[name](bot))
module.exports = bot
我无法在任何地方看到 process.env.BOT_KEY
声明。所以基本上 Key
是未定义的。
要设置BOT_KEY
环境变量,你应该用
启动节点
BOT_KEY='something' node <filename>
// or
export the BOT_KEY
// or
use `dotenv` and set the config in the config file.
办案方式:
const bot = bb({
....
key: process.env.BOT_KEY || "some secret key",
....
});
我不知道如何解决这个问题
- $
rm -rf package-lock.json node_modules <-- you need both
- $
npm install
- 插入稳定版本的节点 (10.16.0)
这是我的package.json
{
"name": "xxxx",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "supervisor -i node_modules index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.0",
"bot-brother": "^2.1.5",
"chalk": "^2.4.1",
"cors": "^2.8.4",
"date-fns": "^1.29.0",
"dotenv": "^4.0.0",
"express": "^4.15.4",
"helmet": "^3.8.1",
"joi": "^10.6.0",
"morgan": "^1.9.1",
"pg": "^7.6.1",
"raven": "^2.2.1",
"supervisor": "^0.12.0"
}
}
当我尝试 npm start
时收到此错误
如果您需要其他文件,我很乐意 post :)
我不知道该怎么办,我该如何解决?
更新
根据要求,这是 bot.js
const bb = require('bot-brother');
const fs = require("fs");
const path = require('path');
const basename = path.basename(__filename);
const bot = bb({
key: process.env.BOT_KEY,
sessionManager: bb.sessionManager.redis({ port: process.env.REDIS_PORT, host: process.env.REDIS_HOST }),
polling: { interval: 5, timeout: 65 }
});
//middlewares
bot.use('before', bb.middlewares.typing());
const actions = {}
//load all actions wrappers
fs
.readdirSync(__dirname + "/actions")
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(file => {
const name = file.replace(".js", "")
actions[name] = require(path.join(__dirname + "/actions", file));
});
//load all actions
Object.keys(actions).forEach(name => actions[name](bot))
module.exports = bot
我无法在任何地方看到 process.env.BOT_KEY
声明。所以基本上 Key
是未定义的。
要设置BOT_KEY
环境变量,你应该用
BOT_KEY='something' node <filename>
// or
export the BOT_KEY
// or
use `dotenv` and set the config in the config file.
办案方式:
const bot = bb({
....
key: process.env.BOT_KEY || "some secret key",
....
});