当前位置:网站首页>FE - Eggjs 结合 Typeorm 出现连接不了数据库
FE - Eggjs 结合 Typeorm 出现连接不了数据库
2022-07-02 06:21:00 【原小明】
问题
eggjs 结合 typeorm 打包部署的时候,一致报错,刚开始还以为是 eggjs 的问题
[egg-scripts] Got error when startup:
[egg-scripts] at createScript (vm.js:251:10)
[egg-scripts] at Object.runInThisContext (vm.js:303:10)
[egg-scripts] at Module._compile (internal/modules/cjs/loader.js:656:28)
[egg-scripts] at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
[egg-scripts] at Module.load (internal/modules/cjs/loader.js:598:32)
[egg-scripts] at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
[egg-scripts] at Function.Module._load (internal/modules/cjs/loader.js:529:3)
[egg-scripts] at Module.require (internal/modules/cjs/loader.js:636:17)
[egg-scripts] at require (internal/modules/cjs/helpers.js:20:18)
[egg-scripts]
[egg-scripts] pid: 30800
[egg-scripts] hostname: labelnet
[egg-scripts]
[egg-scripts] 2019-03-05 15:17:28,085 ERROR 30796 [-/127.0.0.1/-/1ms GET /] nodejs.SyntaxError: Unexpected token {
[egg-scripts] (function (exports, require, module, __filename, __dirname) { import {
[egg-scripts] ^
[egg-scripts]
[egg-scripts] SyntaxError: Unexpected token {
[egg-scripts] at new Script (vm.js:79:7)
[egg-scripts] at createScript (vm.js:251:10)
[egg-scripts] at Object.runInThisContext (vm.js:303:10)
[egg-scripts] at Module._compile (internal/modules/cjs/loader.js:656:28)
[egg-scripts] at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
[egg-scripts] at Module.load (internal/modules/cjs/loader.js:598:32)
[egg-scripts] at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
[egg-scripts] at Function.Module._load (internal/modules/cjs/loader.js:529:3)
[egg-scripts] at Module.require (internal/modules/cjs/loader.js:636:17)
[egg-scripts] at require (internal/modules/cjs/helpers.js:20:18)
eggjs 的 issues 都看过类似的问题了 ,
https://github.com/eggjs/egg/issues/2388
但官网文档已经明确说明,先回加载 js 文件 后加载 ts 文件,一直以为是 eggjs 的问题;
没有想到是 typeorm 的配置问题,entity 配置的是 ts 文件,生产环境需要配置 js 文件
typeorm 并不会自动加载 entity 的 js 文件
解决
开发环境 entity 加载 ts 文件 ,生产环境 加载 js 文件
"db_dev": {
"database": "ruisite-dash-server",
"host": "127.0.0.1",
"port": "3306",
"username": "root",
"password": "root",
"logging": true,
"entities": ["app/entity/*.ts", "app/entity/*/*.ts"]
}
"db_production": {
"database": "ruisite-dash-server",
"host": "192.168.100.10",
"port": "3306",
"username": "root",
"password": "root",
"logging": true,
"entities": ["app/entity/*.js", "app/entity/*/*.js"]
}
边栏推荐
猜你喜欢
【张三学C语言之】—深入理解数据存储
Sudo right raising
阿里云MFA绑定Chrome浏览器
Contest3147 - game 38 of 2021 Freshmen's personal training match_ E: Listen to songs and know music
Redis——大Key問題
BGP报文详细解释
深入学习JVM底层(三):垃圾回收器与内存分配策略
Redis——Cluster数据分布算法&哈希槽
代码技巧——Controller参数注解@RequestParam
Code skills - Controller Parameter annotation @requestparam
随机推荐
LeetCode 90. 子集 II
Network related knowledge (Hardware Engineer)
Invalid operation: Load into table ‘sources_orderdata‘ failed. Check ‘stl_load_errors‘ system table
The difference between session and cookies
Ruijie ebgp configuration case
BGP routing optimization rules and notification principles
Redis——热点key问题
Learn about various joins in SQL and their differences
MySql索引
The real definition of open source software
LeetCode 27. Removing Elements
ROS create workspace
ShardingSphere-JDBC篇
BGP 路由优选规则和通告原则
Redis - cluster data distribution algorithm & hash slot
Code skills - Controller Parameter annotation @requestparam
Linear DP (split)
Decryption skills of encrypted compressed files
一口气说出 6 种实现延时消息的方案
CUDA中的函数执行空间说明符