R
Railway6mo ago
PS

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /app/src/index.ts

Hello everyone! I urgently need your help, cause my service is down for almost a day. I have a telegram bot running on railway and everything was fine since April. Yet today after DB migration the service was restarted and I got the error ERR_UNKNOWN_FILE_EXTENSION (see title). I'm using ts-node as a runtime, e.g I have "start": "ts-node --esm src/index.ts" in scripts, esm is on in tsconfig though in package.json I never used "type": "module". I can run the script locally without any problem, but it constantly fails on deployment:
gptitor@1.4.0 start ts-node --esm src/index.ts TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /app/src/index.ts at new NodeError (node:internal/errors:405:5) at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:136:11) at defaultGetFormat (node:internal/modules/esm/get_format:182:36) at defaultLoad (node:internal/modules/esm/load:101:20) at nextLoad (node:internal/modules/esm/hooks:864:28) at load (/app/node_modules/ts-node/dist/child/child-loader.js:19:122) at nextLoad (node:internal/modules/esm/hooks:864:28) at Hooks.load (node:internal/modules/esm/hooks:447:26) at MessagePort.handleMessage (node:internal/modules/esm/worker:196:24) at [nodejs.internal.kHybridDispatch] (node:internal/event_target:786:20) { code: 'ERR_UNKNOWN_FILE_EXTENSION' }
I used it thins way from the very beginning — all was good. It started to fail only today. Do you have any idea what is wrong?
Solution:
I added "extends": "ts-node/node16/tsconfig.json" into tsconfig.json Replaced NodeNext with ESNext for module setting Added "type": "module" to package.json...
Jump to solution
9 Replies
Percy
Percy6mo ago
Project ID: 9cae3755-6efb-47fa-8f93-76003363ae90
PS
PS6mo ago
Project ID: 9cae3755-6efb-47fa-8f93-76003363ae90
Brody
Brody6mo ago
does this help? https://stackoverflow.com/a/62099904/13155318 maybe even move to tsup?
PS
PS6mo ago
Not really. But I finally resolved it on my own
Brody
Brody6mo ago
what was the issue?
Solution
PS
PS6mo ago
I added "extends": "ts-node/node16/tsconfig.json" into tsconfig.json Replaced NodeNext with ESNext for module setting Added "type": "module" to package.json Replaced launch command "start": "ts-node src/index.ts" with "start": "node --loader ts-node/esm ./src/index.ts"
PS
PS6mo ago
As I mentioned above in description locally everything was fine and most of these changes are redundant. But only these settings were enough for railway runtime
Brody
Brody6mo ago
well im glad you solved it and thank you for the detailed break down, that could help someone in the future!
PS
PS6mo ago
How can I mark this thread as Solved?