问题描述:
使用官方 demo,通过tsc
命令编译代码,在 build 目录执行node index
,即可发现如下错误
EntityMetadataNotFound: No metadata for "User" was found.
at new EntityMetadataNotFoundError (/Users/qianshan/code/node/typeorm/Test/node_modules/typeorm/error/EntityMetadataNotFoundError.js:10:28)
at Connection.getMetadata (/Users/qianshan/code/node/typeorm/Test/node_modules/typeorm/connection/Connection.js:337:19)
at /Users/qianshan/code/node/typeorm/Test/node_modules/typeorm/persistence/EntityPersistExecutor.js:71:80
at Array.forEach (<anonymous>)
at EntityPersistExecutor.<anonymous> (/Users/qianshan/code/node/typeorm/Test/node_modules/typeorm/persistence/EntityPersistExecutor.js:66:54)
...
错误显示没有找到 User 的数据定义,为什么会找不到呢?因为TypeORM运行依赖配置文件ormconfig.json
,其中entities字段指定了元数据的路径,entities 默认值为
[
"src/entity/**/*.ts"
]
当在build目录下运行的时候,entities 被解释为build/src/entity/**/*.ts
,所以找不到对应的元数据,另外ts编译后的文件后缀为.js
,所以如果要正常运行,需要将ormconfig.json
中的entities
改为
[
"entity/**/*.js"
]
Comments(1)
If you’re used to the tap-to-click gesture on your Mac, you can enable this functionality for the iPad by going to Settings > General > Trackpad. Here, tap on the toggle next to the “Tap to Click” option.