我正在使用主express应用程序中的类创建一个命令行脚本。
bin/utils/
âââ sync-buyers.ts
âââ tsconfig.json
主express应用程序已启动
/app
使用
import '@/foo/bar/thing
.
tsconfig.json
主应用程序的,如下所示:
"paths": {
"@/*": ["*"],
"*": [
"node_modules/*",
"app/typings/*"
]
}
},
"include": ["app/**/*", "test/**/*"],
"exclude": ["app/**/*.test.ts", "/__tests__/", "/__mocks__/", "/__snapshots__/", "app/**/__mocks__/"],
"files": ["typings/global.d.ts"]
脚本执行
我正在测试是否可以从主应用程序导入,因此我创建了一个
sayHello()
作用
#!/usr/bin/env ts-node
/* tslint:disable */
import { sayHello } from '../../app/services/v2/oapp';
sayHello();
TSError: ⨯ Unable to compile TypeScript:
../../app/services/v2/oapp.ts(9,19): error TS2307: Cannot find module
'@/helpers/fetch'.
../../app/services/v2/oapp.ts(10,31): error TS2307: Cannot find module
'@/services/v2/buyer'.
../../app/services/v2/oapp.ts(11,51): error TS2307: Cannot find module
'@/http/HttpHeader'.
总结: