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:
[email protected] 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:Jump to 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...9 Replies
Project ID:
9cae3755-6efb-47fa-8f93-76003363ae90
Project ID:
9cae3755-6efb-47fa-8f93-76003363ae90
Not really. But I finally resolved it on my own
what was the issue?
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
Replaced launch command "start": "ts-node src/index.ts"
with "start": "node --loader ts-node/esm ./src/index.ts"
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
well im glad you solved it and thank you for the detailed break down, that could help someone in the future!
How can I mark this thread as Solved?