我的项目一直在使用ts-node
混合运行 JavaScript 和 TypeScript。最近它停止工作,没有明显的原因。在最简单的层面上,这是它的运行方式和它产生的错误:
$ TS_NODE_PROJECT=./tsconfig.json ../../node_modules/.bin/ts-node app.js MSTR-1513
INFO | Arrow/1.6.0
No deployment manifest found
Uncaught Exception Could not find sourceFile: '/Users/jonah/Projects/myapp/server/src/v1/route/Routes.ts' in [].
Error: Could not find sourceFile: '/Users/jonah/Projects/myapp/server/src/v1/route/Routes.ts' in [].
at getValidSourceFile (/Users/jonah/Projects/myapp/node_modules/typescript/lib/typescript.js:122211:23)
at Object.getEmitOutput (/Users/jonah/Projects/myapp/node_modules/typescript/lib/typescript.js:122580:30)
at getOutput (/Users/jonah/Projects/myapp/node_modules/ts-node/src/index.ts:354:30)
at Object.compile (/Users/jonah/Projects/myapp/node_modules/ts-node/src/index.ts:395:32)
at Module.m._compile (/Users/jonah/Projects/myapp/node_modules/ts-node/src/index.ts:473:43)
at Module._extensions..js (module.js:663:10)
at Object.require.extensions.(anonymous function) [as .ts] (/Users/jonah/Projects/myapp/node_modules/ts-node/src/index.ts:476:12)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
摘录app.js
:
const Routes = require('./v1/route/Routes').default;
server.app.use('/v1', new Routes().router);
我对这部分错误感到非常困惑:Could not find sourceFile: '/Users/jonah/Projects/myapp/server/src/v1/route/Routes.ts'
. 我可以将该确切路径粘贴到终端中,然后查看该文件确实存在。这里是tsconfig.json
:
{
"compileOnSave": true,
"compilerOptions": {
"allowJs": false,
"removeComments": true,
"noImplicitAny" : false,
"module": "commonjs",
"target": "es2017",
"sourceMap": true,
"watch": false,
"types": ["mocha"],
"forceConsistentCasingInFileNames": false
},
"include": [
"./v1/**/*.ts",
"../test/v1/**/*.ts"
],
"exclude": [
"../../node_modules"
]
}
运行当前最新的 TypeScript (3.5.2) 和 ts-node (8.3.0)。什么样的情况可能会产生这种错误?我什至尝试弄乱include
s 以确保覆盖正在导入的文件。单独运行 TypeScript 编译器就可以了。
../../node_modules/.bin/tsc --project tsconfig.json