Execute an external TS file in a T3 Stack app

Hello, I have my T3 stack up running and I need to execute a ts file I already searched online and tried using node-ts and tsc but neither work. Do you have any idea about how I can do this ? Thanks !
6 Replies
bedesqui
bedesqui2y ago
wym executing a file? Executing as in locally in a terminal?
hugolepot
hugolepot2y ago
yes, in my case I store information in a db and i need to update all the record of the database but I don't want any access on the app itself just be able to update it by executing a file. If you need the code of the file I try to execute I can provide it to you !
Matvey
Matvey2y ago
why didn't ts-node work? did you get an error, or what?
hugolepot
hugolepot2y ago
Yes i got an error : Command :
npx ts-node src/scripts/updateFiles.ts
npx ts-node src/scripts/updateFiles.ts
I got this error :
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /home/hugo/web/replayer/src/scripts/updateFiles.ts
at new NodeError (node:internal/errors:399:5)
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:79:11)
at defaultGetFormat (node:internal/modules/esm/get_format:121:38)
at defaultLoad (node:internal/modules/esm/load:81:20)
at nextLoad (node:internal/modules/esm/loader:163:28)
at ESMLoader.load (node:internal/modules/esm/loader:605:26)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:457:22)
at new ModuleJob (node:internal/modules/esm/module_job:64:26)
at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:480:17)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:434:34) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /home/hugo/web/replayer/src/scripts/updateFiles.ts
at new NodeError (node:internal/errors:399:5)
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:79:11)
at defaultGetFormat (node:internal/modules/esm/get_format:121:38)
at defaultLoad (node:internal/modules/esm/load:81:20)
at nextLoad (node:internal/modules/esm/loader:163:28)
at ESMLoader.load (node:internal/modules/esm/loader:605:26)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:457:22)
at new ModuleJob (node:internal/modules/esm/module_job:64:26)
at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:480:17)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:434:34) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
@bedesqui Do you have any ideas of how I can fix this problem please ?
bedesqui
bedesqui2y ago
If you have "type": "module" set for the project, maybe running npx ts-node --esm src/scripts/updateFiles.ts will work I think ts-node expects cjs
hugolepot
hugolepot2y ago
Thanks @bedesqui With "type": module and npx ts-node --esm src/scripts/updateFiles.ts I got this error :
/home/hugo/web/replayer/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:366
throw new ERR_MODULE_NOT_FOUND(
^
CustomError: Cannot find module '/home/hugo/web/replayer/src/utils/translater/HandManagerV2' imported from /home/hugo/web/replayer/src/scripts/updateFiles.ts
at finalizeResolution (/home/hugo/web/replayer/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:366:11)
at moduleResolve (/home/hugo/web/replayer/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:801:10)
at Object.defaultResolve (/home/hugo/web/replayer/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:912:11)
at /home/hugo/web/replayer/node_modules/ts-node/src/esm.ts:218:35
at entrypointFallback (/home/hugo/web/replayer/node_modules/ts-node/src/esm.ts:168:34)
at /home/hugo/web/replayer/node_modules/ts-node/src/esm.ts:217:14
at addShortCircuitFlag (/home/hugo/web/replayer/node_modules/ts-node/src/esm.ts:409:21)
at resolve (/home/hugo/web/replayer/node_modules/ts-node/src/esm.ts:197:12)
at resolve (/home/hugo/web/replayer/node_modules/ts-node/src/child/child-loader.ts:15:39)
at nextResolve (node:internal/modules/esm/loader:163:28)
/home/hugo/web/replayer/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:366
throw new ERR_MODULE_NOT_FOUND(
^
CustomError: Cannot find module '/home/hugo/web/replayer/src/utils/translater/HandManagerV2' imported from /home/hugo/web/replayer/src/scripts/updateFiles.ts
at finalizeResolution (/home/hugo/web/replayer/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:366:11)
at moduleResolve (/home/hugo/web/replayer/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:801:10)
at Object.defaultResolve (/home/hugo/web/replayer/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:912:11)
at /home/hugo/web/replayer/node_modules/ts-node/src/esm.ts:218:35
at entrypointFallback (/home/hugo/web/replayer/node_modules/ts-node/src/esm.ts:168:34)
at /home/hugo/web/replayer/node_modules/ts-node/src/esm.ts:217:14
at addShortCircuitFlag (/home/hugo/web/replayer/node_modules/ts-node/src/esm.ts:409:21)
at resolve (/home/hugo/web/replayer/node_modules/ts-node/src/esm.ts:197:12)
at resolve (/home/hugo/web/replayer/node_modules/ts-node/src/child/child-loader.ts:15:39)
at nextResolve (node:internal/modules/esm/loader:163:28)
Want results from more Discord servers?
Add your server