Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

egg + ts dev bug #2330

Closed
HaveF opened this issue Apr 6, 2018 · 8 comments
Closed

egg + ts dev bug #2330

HaveF opened this issue Apr 6, 2018 · 8 comments

Comments

@HaveF
Copy link

HaveF commented Apr 6, 2018

  • Node Version:
    node --version
    v9.10.1
  • Egg Version:
    "egg": "^2.6.0",
  • Plugin Name:
  • Plugin Version:
  • Platform:
  • Mini Showcase Repository:

完全按照 当 Egg 遇到 TypeScript,收获茶叶蛋一枚 · Issue #27 · atian25/blog中的快速入门部分尝试

$ npx egg-init --type=ts showcase
$ cd showcase && npm i
$ npm run dev

先注释了一下home.ts中的
// ctx.body = await ctx.service.test.sayHi('egg');
然后再取消注释
npm run dev就崩了

npm run dev

> [email protected] dev /Users/HaveF/Desktop/newTech/eggWithTs
> egg-bin dev -r egg-ts-helper/register

[egg-ts-helper] These file was deleted because of the same name ts file was exist!

  /Users/HaveF/Desktop/newTech/eggWithTs/app/controller/home.js

2018-04-06 18:47:08,312 INFO 39788 [master] node version v9.10.1
2018-04-06 18:47:08,313 INFO 39788 [master] egg version 2.6.0
[egg-ts-helper] /Users/HaveF/Desktop/newTech/eggWithTs/typings/app/controller/index.d.ts created
[egg-ts-helper] /Users/HaveF/Desktop/newTech/eggWithTs/typings/config/index.d.ts created
[egg-ts-helper] /Users/HaveF/Desktop/newTech/eggWithTs/typings/app/service/index.d.ts created
2018-04-06 18:47:09,871 INFO 39788 [master] agent_worker#1:39793 started (1554ms)
2018-04-06 18:47:11,352 INFO 39788 [master] egg started on http://127.0.0.1:7001 (3038ms)
2018-04-06 18:47:21,069 WARN 39793 [agent:development] reload worker because /Users/HaveF/Desktop/newTech/eggWithTs/app/controller/home.js rename
[egg-ts-helper] /Users/HaveF/Desktop/newTech/eggWithTs/typings/app/controller/index.d.ts created

/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-core/lib/loader/file_loader.js:83
            if (!this.options.override) throw new Error(`can't overwrite property '${properties}' from ${target[property][FULLPATH]} by ${item.fullpath}`);
                                              ^
Error: can't overwrite property 'home' from /Users/HaveF/Desktop/newTech/eggWithTs/app/controller/home.js by /Users/HaveF/Desktop/newTech/eggWithTs/app/controller/home.ts
    at item.properties.reduce (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-core/lib/loader/file_loader.js:83:47)
    at Array.reduce (<anonymous>)
    at FileLoader.load (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-core/lib/loader/file_loader.js:78:23)
    at AppWorkerLoader.loadToApp (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-core/lib/loader/egg_loader.js:360:25)
    at AppWorkerLoader.loadController (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-core/lib/loader/mixin/controller.js:47:10)
    at AppWorkerLoader.load (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg/lib/loader/app_worker_loader.js:39:10)
    at new Application (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg/lib/application.js:55:19)
    at Object.<anonymous> (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-cluster/lib/app_worker.js:13:13)
    at Module._compile (module.js:649:30)
    at Object.Module._extensions..js (module.js:660:10)
[2018-04-06 18:47:23.374] [cfork:master:39788] worker:39797 disconnect (exitedAfterDisconnect: false, state: disconnected, isDead: false, worker.disableRefork: true)
[2018-04-06 18:47:23.374] [cfork:master:39788] don't fork, because worker:39797 will be kill soon
2018-04-06 18:47:23,374 INFO 39788 [master] app_worker#2:39797 disconnect, suicide: false, state: disconnected, current workers: ["1","2"]
[2018-04-06 18:47:23.376] [cfork:master:39788] worker:39797 exit (code: 1, exitedAfterDisconnect: false, state: dead, isDead: true, isExpected: false, worker.disableRefork: true)
2018-04-06 18:47:23,381 ERROR 39788 nodejs.AppWorkerDiedError: [master] app_worker#2:39797 died (code: 1, signal: null, suicide: false, state: dead), current workers: []
    at Master.onAppExit (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-cluster/lib/master.js:387:21)
    at Master.emit (events.js:180:13)
    at Messenger.sendToMaster (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-cluster/lib/utils/messenger.js:122:17)
    at Messenger.send (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-cluster/lib/utils/messenger.js:87:12)
    at EventEmitter.cluster.on (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-cluster/lib/master.js:264:22)
    at EventEmitter.emit (events.js:185:15)
    at ChildProcess.worker.process.once (internal/cluster/master.js:194:13)
    at Object.onceWrapper (events.js:272:13)
    at ChildProcess.emit (events.js:180:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:12)
name: 'AppWorkerDiedError'
pid: 39788
hostname: luodeMacBook-Pro.local

[2018-04-06 18:47:23.383] [cfork:master:39788] worker:39794 disconnect (exitedAfterDisconnect: true, state: disconnected, isDead: false, worker.disableRefork: false)
[2018-04-06 18:47:23.383] [cfork:master:39788] don't fork new work (refork: false)
2018-04-06 18:47:23,383 INFO 39788 [master] app_worker#1:39794 disconnect, suicide: true, state: disconnected, current workers: []
[2018-04-06 18:47:23.396] [cfork:master:39788] worker:39794 exit (code: 0, exitedAfterDisconnect: true, state: dead, isDead: true, isExpected: true, worker.disableRefork: false)
2018-04-06 18:47:35,991 WARN 39793 [agent:development] reload worker because /Users/HaveF/Desktop/newTech/eggWithTs/app/controller/home.js change

/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-core/lib/loader/file_loader.js:83
            if (!this.options.override) throw new Error(`can't overwrite property '${properties}' from ${target[property][FULLPATH]} by ${item.fullpath}`);
                                              ^
Error: can't overwrite property 'home' from /Users/HaveF/Desktop/newTech/eggWithTs/app/controller/home.js by /Users/HaveF/Desktop/newTech/eggWithTs/app/controller/home.ts
    at item.properties.reduce (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-core/lib/loader/file_loader.js:83:47)
    at Array.reduce (<anonymous>)
    at FileLoader.load (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-core/lib/loader/file_loader.js:78:23)
    at AppWorkerLoader.loadToApp (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-core/lib/loader/egg_loader.js:360:25)
    at AppWorkerLoader.loadController (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-core/lib/loader/mixin/controller.js:47:10)
    at AppWorkerLoader.load (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg/lib/loader/app_worker_loader.js:39:10)
    at new Application (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg/lib/application.js:55:19)
    at Object.<anonymous> (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-cluster/lib/app_worker.js:13:13)
    at Module._compile (module.js:649:30)
    at Object.Module._extensions..js (module.js:660:10)
[2018-04-06 18:47:37.053] [cfork:master:39788] worker:39800 disconnect (exitedAfterDisconnect: false, state: disconnected, isDead: false, worker.disableRefork: true)
[2018-04-06 18:47:37.053] [cfork:master:39788] don't fork, because worker:39800 will be kill soon
2018-04-06 18:47:37,054 INFO 39788 [master] app_worker#3:39800 disconnect, suicide: false, state: disconnected, current workers: ["3"]
[2018-04-06 18:47:37.054] [cfork:master:39788] worker:39800 exit (code: 1, exitedAfterDisconnect: false, state: dead, isDead: true, isExpected: false, worker.disableRefork: true)
2018-04-06 18:47:37,055 ERROR 39788 nodejs.AppWorkerDiedError: [master] app_worker#3:39800 died (code: 1, signal: null, suicide: false, state: dead), current workers: []
    at Master.onAppExit (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-cluster/lib/master.js:387:21)
    at Master.emit (events.js:180:13)
    at Messenger.sendToMaster (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-cluster/lib/utils/messenger.js:122:17)
    at Messenger.send (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-cluster/lib/utils/messenger.js:87:12)
    at EventEmitter.cluster.on (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-cluster/lib/master.js:264:22)
    at EventEmitter.emit (events.js:185:15)
    at ChildProcess.worker.process.once (internal/cluster/master.js:194:13)
    at Object.onceWrapper (events.js:272:13)
    at ChildProcess.emit (events.js:180:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:12)
name: 'AppWorkerDiedError'
pid: 39788
hostname: luodeMacBook-Pro.local

2018-04-06 18:47:51,375 ERROR 39788 nodejs.ClusterWorkerExceptionError: [master] 1 agent and 0 worker(s) alive, exit to avoid unknown state
    at Manager.Master.workerManager.on (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-cluster/lib/master.js:133:19)
    at Manager.emit (events.js:180:13)
    at Timeout.timer.setInterval [as _onTimeout] (/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-cluster/lib/utils/manager.js:67:14)
    at ontimeout (timers.js:466:11)
    at tryOnTimeout (timers.js:304:5)
    at Timer.listOnTimeout (timers.js:267:5)
name: 'ClusterWorkerExceptionError'
count: { agent: 1, worker: 0 }
pid: 39788
hostname: luodeMacBook-Pro.local

2018-04-06 18:47:51,376 ERROR 39788 [master] exit with code:1
2018-04-06 18:47:51,388 ERROR 39793 [agent_worker] receive disconnect event on child_process fork mode, exiting with code:110
⚠️  Error: /Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg-bin/lib/start-cluster {"typescript":true,"baseDir":"/Users/HaveF/Desktop/newTech/eggWithTs","framework":"/Users/HaveF/Desktop/newTech/eggWithTs/node_modules/egg","workers":1} exit with code 1
⚠️  Command Error, enable `DEBUG=common-bin` for detail
2018-04-06 18:47:51,391 ERROR 39793 [agent_worker] exit with code:110
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `egg-bin dev -r egg-ts-helper/register`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/HaveF/.npm/_logs/2018-04-06T10_47_51_403Z-debug.log
@atian25
Copy link
Member

atian25 commented Apr 6, 2018

看起来你是 tsc 过,导致 js 和 ts 文件同时存在,loader 加载了 2 次。
执行下 npm run clean

你是不是开了什么插件之类的,有 tsc 在后台自动编译了?

@HaveF
Copy link
Author

HaveF commented Apr 6, 2018

感谢天猪
奇怪, 我并没有做tsc之类的动作啊...前面用的是webstorm的默认配置

我删除又重做了下, 这次提示是否将ts编译成js, 选了no, 发现确实没有问题了
(上一次好像没有做任何类似动作)
感谢感谢

另外这个错误有可能在什么地方表示的更清晰些吗? 比如你说的loader加载了两次?

@HaveF HaveF closed this as completed Apr 6, 2018
@atian25
Copy link
Member

atian25 commented Apr 6, 2018

Error: can't overwrite property 'home' from /Users/HaveF/Desktop/newTech/eggWithTs/app/controller/home.js by /Users/HaveF/Desktop/newTech/eggWithTs/app/controller/home.ts

写的很清楚了,先加载了 js 文件,然后再加载了 ts

@waitingsong
Copy link
Contributor

waitingsong commented Apr 7, 2018

@atian25 我觉得还是把开发目录和编译目录分开的比较好。虽然根据日志能清楚查出问题,但这个不是解决办法。估计以后还会有人会遇到相同问题。有看日志的可能可以解决,没仔细看日志的就只有上来报bug……

@atian25
Copy link
Member

atian25 commented Apr 7, 2018

在规范里面没有约束编译目录,只是对开发期做了约束,开发者自行配置就好了。他这个问题是 webstorm 自带的一个 watcher 搞的

@atian25
Copy link
Member

atian25 commented Apr 7, 2018

不看日志只会报 issue 的谁都没辙

@nimoc
Copy link

nimoc commented May 1, 2019

今天遇到相同的问题,留个备注防止后人踩坑。

atom-typescript 在 tsconfig.json 设置 compileOnSave: true 后会自动编译,就跟npm run dev 的编译冲突了。 关闭 "compileOnSave":false 即可


后续进展

直接使用 midway (基于 egg 支持 typescript 依赖注入)

@nimoc
Copy link

nimoc commented May 1, 2019

如果希望使用ide的编译,以避免报错出现在终端/命令行中。 设置 tsconfig.json compileOnSave 为 true
修改package.json 中 egg.typescript 为false
config/config.default.ts 新增

let reloadPattern = ['**']
  if (require('../package.json').egg.typescript === false) {
    reloadPattern.push('!**/*.ts')
  }
  config.development = {
    reloadPattern
  }

npm run dev 的 package.json 中 要改为 ""dev": "tsc && egg-bin dev","

以后想切换回来就修改 compileOnSave 和 typescript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants