[英]How can I get a Typescript script to use the paths defined in tsconfig?
In my NodeJS/Typescript project, I created a script database-init.script.ts
that I run to initialize the database with sample data.在我的 NodeJS/Typescript 项目中,我创建了一个脚本database-init.script.ts
,我运行它来使用示例数据初始化数据库。
My package.json looks like this:我的 package.json 看起来像这样:
{
"name": "myproject",
....
"scripts": {
...
"mongodb-setup": "tsc ./scripts/mongodb-setup.ts && node ./scripts/mongo-setup.js"
}
The problem is that the script imports some files that themselves utilize tsconfig paths
shortcuts.问题是脚本导入了一些本身使用 tsconfig paths
快捷方式的文件。 For example some files have例如一些文件有
import {AccountSchema} from '@schemas/account.schema'
...
My script fails because it doesn't recognize these.我的脚本失败了,因为它无法识别这些。 It gives me它给了我
error TS2307: Cannot find module '@schemas/account.schema' or its corresponding type declarations.
1 import {AccountSchema} from '@schemas/account.schema";
How can I get a script to recognize tsconfig-defined paths, without compiling the entire project?如何在不编译整个项目的情况下获取脚本来识别 tsconfig 定义的路径?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.