Thursday, 27 May 2021

TS-Node: Could not find sourceFile

My project has been using ts-node to run a mix of JavaScript and TypeScript. Recently it stopped working, without an obvious reason. At the most simple level, here is how it's run and the error it produces:

$ 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)

Excerpt of app.js:

const Routes = require('./v1/route/Routes').default;
server.app.use('/v1', new Routes().router);

I'm very confused by this part of the error: Could not find sourceFile: '/Users/jonah/Projects/myapp/server/src/v1/route/Routes.ts'. I can paste that exact path into the terminal and and see that the file does in fact exist. Here is 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"
  ]
}

Running currently latest of TypeScript (3.5.2) and ts-node (8.3.0). What type of circumstances might produce this kind of error? I've even tried messing around with the includes to make sure the file being imported is covered. Running the TypeScript compiler on its own works just fine.

../../node_modules/.bin/tsc --project tsconfig.json


from TS-Node: Could not find sourceFile

No comments:

Post a Comment