Egg.js egg-mysql 连接MySQL 报 AppWorkerDiedError 错误

杜尼卜
  • 11k

问题描述

> egg-bin dev

[egg-ts-helper] create typings/app/controller/index.d.ts (3ms)
[egg-ts-helper] create typings/config/index.d.ts (36ms)
[egg-ts-helper] create typings/app/index.d.ts (0ms)
2020-02-27 22:51:19,094 INFO 3754 [master] node version v10.16.3
2020-02-27 22:51:19,096 INFO 3754 [master] egg version 2.26.0
/Users/zhangbing/github/CodeTest/react_blog/service/node_modules/egg-core/lib/loader/mixin/plugin.js:207
    if (!('enable' in plugin)) {
                   ^

TypeError: Cannot use 'in' operator to search for 'enable' in egg-mysql
    at AgentWorkerLoader.normalizePluginConfig (/Users/zhangbing/github/CodeTest/react_blog/service/node_modules/egg-core/lib/loader/mixin/plugin.js:207:20)
    at AgentWorkerLoader.readPluginConfigs (/Users/zhangbing/github/CodeTest/react_blog/service/node_modules/egg-core/lib/loader/mixin/plugin.js:182:14)
    at AgentWorkerLoader.loadPlugin (/Users/zhangbing/github/CodeTest/react_blog/service/node_modules/egg-core/lib/loader/mixin/plugin.js:62:29)
    at AgentWorkerLoader.loadConfig (/Users/zhangbing/github/CodeTest/react_blog/service/node_modules/egg/lib/loader/agent_worker_loader.js:15:10)
    at new EggApplication (/Users/zhangbing/github/CodeTest/react_blog/service/node_modules/egg/lib/egg.js:54:17)
    at new Agent (/Users/zhangbing/github/CodeTest/react_blog/service/node_modules/egg/lib/agent.js:22:5)
    at Object.<anonymous> (/Users/zhangbing/github/CodeTest/react_blog/service/node_modules/egg-cluster/lib/agent_worker.js:28:15)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
2020-02-27 22:51:20,141 ERROR 3754 nodejs.AgentWorkerDiedError: [master] agent_worker#1:3759 died (code: 1, signal: null)
    at Master.onAgentExit (/Users/zhangbing/github/CodeTest/react_blog/service/node_modules/egg-cluster/lib/master.js:425:17)
    at Master.emit (events.js:198:13)
    at Messenger.sendToMaster (/Users/zhangbing/github/CodeTest/react_blog/service/node_modules/egg-cluster/lib/utils/messenger.js:137:17)
    at Messenger.send (/Users/zhangbing/github/CodeTest/react_blog/service/node_modules/egg-cluster/lib/utils/messenger.js:102:12)
    at ChildProcess.agentWorker.once (/Users/zhangbing/github/CodeTest/react_blog/service/node_modules/egg-cluster/lib/master.js:289:22)
    at Object.onceWrapper (events.js:286:20)
    at ChildProcess.emit (events.js:198:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
name: "AgentWorkerDiedError"
pid: 3754
hostname: ibing.local

2020-02-27 22:51:20,141 ERROR 3754 [master] agent_worker#1:3759 start fail, exiting with code:1
2020-02-27 22:51:20,142 ERROR 3754 [master] exit with code:1
{ Error: /Users/zhangbing/github/CodeTest/react_blog/service/node_modules/egg-bin/lib/start-cluster {"typescript":false,"declarations":true,"workers":1,"baseDir":"/Users/zhangbing/github/CodeTest/react_blog/service","framework":"/Users/zhangbing/github/CodeTest/react_blog/service/node_modules/egg"} exit with code 1
    at ChildProcess.proc.once.code (/Users/zhangbing/github/CodeTest/react_blog/service/node_modules/common-bin/lib/helper.js:56:21)
    at Object.onceWrapper (events.js:286:20)
    at ChildProcess.emit (events.js:198:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12) code: 1 }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! service@1.0.0 dev: `egg-bin dev`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the service@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

问题出现的环境背景及自己尝试过哪些方法

环境信息:

  • OS:Mac OS X 10.15.3
  • Egg.js 2.15.1
  • egg-mysql 3.0.0

MySQL连接信息无误,本地Navicat可以正常操作,搜索了一圈依然没解决,Egg.js官方issues有提到,但貌似没有解决方案

相关代码

config/config.default.js

/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1582792561373_6314';

  // add your middleware config here
  config.middleware = [];

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  config.mysql = {
    // 单数据库信息配置
    client: {
      // host
      host: 'localhost',
      // 端口号
      port: '3306',
      // 用户名
      user: 'root',
      // 密码
      password: '123321',
      // 数据库名
      database: 'react-blog',
    },
    // 是否加载到 app 上,默认开启
    app: true,
    // 是否加载到 agent 上,默认关闭
    agent: false,
  };

  return {
    ...config,
    ...userConfig,
  };
};

config/plugin.js

module.exports = {
  enable: true,
  package: 'egg-mysql',
};
回复
阅读 3.5k
4 个回答

config/plugin.js

module.exports = {
  enable: true,
  package: 'egg-mysql',
};

这里有问题,没有暴露出mysql插件,应该是

module.exports = {
  mysql:{
      enable: true,
      package: 'egg-mysql',}
    };
伟风
  • 1
新手上路,请多包涵

老哥,我也碰到了这个问题,你解决了吗

李里
  • 2
新手上路,请多包涵

今天学习egg.js也遇到了同样的问题,windows 10 mysql 8.0
这个问题刚刚解决了,重新安装了mysql,这个主要是mysql安装的时候有个叫强密码模式导致这种错误的。QQ截图20200304220631.pngQQ截图20200304220448.png

高大丫
  • 2
新手上路,请多包涵

老哥,解决了吗?我也遇到了这个问题

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
你知道吗?

宣传栏