javascript - TS 节点:找不到源文件

标签 javascript typescript file-not-found ts-node

我的项目一直在使用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

最佳答案

我觉得这与循环依赖有关。特别是@Brenne 的回答说:

Changing the order of the imports helped.


根据我的经验,这些莫名其妙的错误总是倾向于循环依赖。
我只熟悉webpack plugin to detect these .但是,您可以尝试删除 require 并查看它是否正确构建。从那里,从 './v1/route/Routes' 中删除其他需要/导入的部分。文件以查看其中是否有任何导致循环 dep

关于javascript - TS 节点:找不到源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56761894/

相关文章:

javascript - 如何使用 .nextUntil 将两个不同的类添加到 <h2> 元素列表中

javascript - 使用 typescript react redux 设置 reducer

angular - 单元测试后关闭 ngx-bootstrap 模式

CodeLite 静态库找不到包含文件

ios - 在 ios 中获取文件未找到错误

javascript - Action 必须是普通对象。使用自定义中间件进行异步操作 - React Native Redux

javascript - 如何从laravel Blade循环获取jQuery的变量类名

javascript - 如何使用 Typescript 在 React 中设置间隔

c++ - 无法从 Mac 上的 C++ 程序读取文件

javascript - `ng-class` 无法处理来自包含模板的功能调用