eggjs / egg

🥚 Born to build better enterprise frameworks and apps with Node.js & Koa
https://eggjs.org
MIT License
18.88k stars 1.81k forks source link

ts项目直接跑npm start报config.keys不存在 #2617

Closed chenyulun closed 6 years ago

chenyulun commented 6 years ago
egg-bot commented 6 years ago

Translation of this issue:


ts project runs npm start directly config.keys does not exist

whxaxes commented 6 years ago

npm start 一般是用于在生产中跑的,而生产代码是需要将 ts 编译成 js,只有在开发的时候,才会使用 ts-node 来跑应用,所以请使用 npm dev

如果要在生产中跑 npm start,请先 tsc 编译一下。

原因是,在生产如果跑 ts-node,会产生无谓的编译开销。

chenyulun commented 6 years ago

keys肯定是有配置的,不然npm run ci生成后也会报错的

atian25 commented 6 years ago

楼上已经说很清楚了, npm start 的前提条件是 tsc 编译,在文档里面有提到的。

chenyulun commented 6 years ago

‘‘ 正式环境下,我们更倾向于把 ts 构建为 js ,建议在 ci 上构建并打包。’’是这句话吗?还是有其他文档提到? 我理解的是可以直接用ts运行,只是推荐使用js, 现在ts直接执行报错,不是开销问题,编译后就不会有问题?难道这不是一个问题吗

atian25 commented 6 years ago

所谓 keys 不存在的原因,就是因为线上 egg 的 loader 根本不会去加载 ts 文件。

线下能加载 ts 是 egg-bin 提供的,ts-node 这个能力只是在 egg-bin 开发期提供的,egg-scripts 不提供。 如果你期望在线上直接运行 ts,那就需要自行引入下。

chenyulun commented 6 years ago

你这么说我就明白了,官方问题没有强制说明,我以为只是推荐

whxaxes commented 6 years ago

@chenyulun 这个我们会在文档里完善一下描述,现在确实会容易让人误解

islishude commented 6 years ago

我也是报这个错误,而且都是编译好了ts文件,为什么还要报这个错误

atian25 commented 6 years ago

@isLishude 要确认下你是否是在编译后的目录下执行的,且编译后的目录下存在 config/config.default.js ,且这个文件是符合 egg 规范的

islishude commented 6 years ago

不好意思我的失误,dockerignore 把 config 文件夹包含进去了。