The `-r` option in `ts-node` is used to preload modules before executing a TypeScript file. However, as of version 8.5.0 of `ts-node`, there have been significant changes that affect the ability to preload TypeScript files directly.
Current Status of Preloading with `-r`
1. Preloading Issues: Users have reported that preloading a TypeScript file using the command `ts-node -r ./config src/index.ts` no longer works as expected in versions greater than 8.4.1. Specifically, environment variables that should be initialized in the preloaded file may remain undefined when the main application starts[1].
2. Reverted Changes: The issue was acknowledged, and a subsequent version (8.5.2) attempted to address it, indicating that the preloading functionality has been under review and modification[1].
3. Workaround: For those needing to preload TypeScript files, one suggested workaround is to ensure you are using a version of `ts-node` that is 8.4.1 or lower, where preloading worked correctly[1].
Conclusion
While you can use the `-r` option with `ts-node` to preload modules, recent updates have introduced complications that may prevent it from functioning as intended for TypeScript files. Users are encouraged to check their `ts-node` version and consider reverting to an earlier version if they rely on this functionality for initializing configurations or environment variables before running their applications.
Citations:[1] https://github.com/TypeStrong/ts-node/issues/910
[2] https://stackoverflow.com/questions/70847216/how-to-preload-typescript-class-with-r-option-of-ts-node
[3] https://www.jsgarden.co/blog/electron-with-typescript-and-vite-as-a-build-system
[4] https://quasar.dev/quasar-cli-vite/supporting-ts/
[5] https://stackoverflow.com/questions/73217517/ts-node-and-custom-loaders
[6] https://github.com/electron/forge/issues/2939
[7] https://github.com/electron-react-boilerplate/electron-react-boilerplate/issues/2974
[8] https://dev.to/_staticvoid/how-to-run-typescript-natively-in-nodejs-with-tsx-3a0c