Repository navigation
ts-node does not auto-register in child processes because it does not set NODE_OPTIONS #1707
Description
Activity
You'll have to set NODE_OPTIONS in order for ts-node to auto-install into child processes. This is not currently something we do automatically, so it would be a feature request to add this. There's probably an issue for this; I recommend doing a search.
Something like this will probably work for you:
NODE_OPTIONS='--require ts-node/register' node ./bot.ts- changed the title
[-]tsconfig doesn't get parsed through to node:child_process | Discord.js Sharding[/-][+]ts-node does not auto-register in child processes because it does not set `NODE_OPTIONS`[/+]on Apr 6, 2022 thanks for the quick anwser.
I have pretty much no experience with node options, but that shouldn't be too difficult to solve with a little research, Not that I know more thanks to you I will try some things outOkay it works like a charm with the Node Options, and it also works with nodemon, thanks for your help again
I gonna report that fix to the dicord.js team, so that this gets more knowledgeable :)
Actually this node-option adds a new problem, that Types somehow don't get parsed the right way anymore, so You can't use this approach with
"noImplicitAny"
set to true, because it will be missing all types- I bet setting TS_NODE_PROJECT and/or TS_NODE_FILES will fix that.…On Thu, Apr 7, 2022, 6:00 AM Snoweuph ***@***.***> wrote: Actually this node-option adds a new problem, that Types somehow don't get parsed the right way anymore, so You can't use this approach with "noImplicitAny" set to true, because it will be missing all types — Reply to this email directly, view it on GitHub <#1707 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAC35OHE26VONQTSKS44FUDVD2W3DANCNFSM5SWOL3VA> . You are receiving this because you commented.Message ID: ***@***.***>
I tried
TS_NODE_PROJECT="./tsconfig.json"
andTS_NODE_FILES="true"
both together and alone, but none of them helped, I'm probably doing something wrong right?or did you mean that I could just disable type checking fo dev only?
Disabling typechecking is IMO always the correct choice. We keep typechecking support for people who really want it, but I never use it. Run
tsc --noEmitif you want to typecheck. There's no reason for every single process you spawn to repeat that work. So yes, I recommend turning on our SWC option which will make everything faster.
https://typestrong.org/ts-node/docs/swcWhen using
--require ts-node/register, ts-node is forced to discover your tsconfig relative to cwd unless you specifyTS_NODE_PROJECT. Also remember that if the child process has a different cwd, and ifTS_NODE_PROJECTis a relative path, then it'll be interpreted relative to the child process's cwd. An easy way to avoid that is to setTS_NODE_PROJECTto an absolute path.However, I suspect that if you add
"swc": trueto your roottsconfig.json, and useNODE_OPTIONS, then that is all that you need. It will be fast and will auto-install into each child process.
https://typestrong.org/ts-node/docs/configuration#via-tsconfigjson-recommended- locked and limited conversation to collaborators
on Apr 7, 2022
Search Terms
Discord
Sharding
ChildProcess
SubProcecss
Expected Behavior
using ts-node (with nodemon or without it) to test without compiling every time, everything should just work fine without any errors that point that the config is set wrong.
Actual Behavior
when running Discord.js Sharding with ts-node it throughs errors that say that import cant be used outside of a module though inside of the tsconfig.json "moduleResolution" is set to "Node".
Steps to reproduce the problem
npm i -g typescript ts-nodenpm i discord.js{ "compilerOptions": { "module": "CommonJS", "target": "ESNext", "moduleResolution": "Node", "esModuleInterop": true, "outDir": "./build", } }ts-node bot.tsthis just works finets-node sharded.tsthis will now result with throwing errors that your not allowed to useimportinside of the bot.tsconst manager = new discord.ShardingManager('./bot.ts', {inside of the compiled sharded.js with './build/bot.js'node build/sharded.jsit works without problemsafter asking that problem on the official discord.js Discord Server and Github The answer I got was that this has nothing to do with discord.js and instead is a problem with ts-node in some way I also looked into the sourcedoe of discordjs but they are just using
node:child_processandnode:worker_threadspackage to achieve sharding. Other Libraries and Frameworks may also be affected by this.minimal reproduction
TypeStrong/ts-node-repros#27
Specifications
{ "compilerOptions": { "module": "CommonJS", "target": "ESNext", "noImplicitAny": true, "sourceMap": true, "importHelpers": true, "forceConsistentCasingInFileNames": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "moduleResolution": "Node", "esModuleInterop": true, "removeComments": true, "outDir": "./build", "baseUrl": ".", "paths": { "@base/*": [ "src/base/*" ], "@baseTypes/*": [ "src/base/types/*" ], "@classes/*": [ "src/base/classes/*" ], "@schema/*": [ "src/base/schema/*" ], "@interactions/*": [ "src/interactions/*" ], "@utils/*": [ "src/utils/*" ], "@assets/*": [ "src/assets/*" ], } }, "tsc-alias": { "replacers": { "base-url": { "enabled": false } } }, "include": [ "src/**/*" ], "exclude": [ "node_modules/**/*" ] }