Closed joeldenning closed 6 months ago
Same here, I want to use node --import tsimp/import
, instead of node --loader ts-node/esm
. Currently, I am using a mentioned workaround with execMap
:
{
"ext": "ts",
+ "execMap": {
+ "ts": "node"
+ },
"env": {
"NODE_OPTIONS": "--import tsimp/import"
}
}
Sorry for the late reply. I've tried to compose multiple replies, and it keeps changing drastically as I start to fully understand the problem (aka: "fully read the ticket"!).
Would it make sense to add support for --import
(in addition to --loader
)? Is it as simple as that?
I'm really not sure what the broader impact is, but I'm guessing (because I've not used these myself) that import
is ESM "require this module" and loader
is commonjs "(actually) require this module".
My gut says that since adding the original loader
support didn't mess up anyone's day, I'd guess adding import
support would land in the same way.
Just let me know (hopefully with a considered response) and I'll get the change in and released :+1:
@remy
I think that's correct, to support both flags.
Usage of --loader
is discouraged (in fact it logs warnings in some Node.js versions), and it is recommended to use --import
flag instead.
You can read more in official Node.js docs:
I just pushed the code but for some reason it's not deploying, so I'll try to sort that out this evening.
:tada: This issue has been resolved in version 3.0.3 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
That's live
nodemon -v
: 2.0.20cross-env IS_LOCAL=true \"NODE_OPTIONS=--import ./register-hooks.js\" IS_RUNNING_LOCALLY=true BASEPLATE_ENV=dev PORT=7601 nodemon --signal SIGINT backend/Server.ts --watch backend --watch migrations --watch frontend --watch docs --ext tsx,ts,js,md,mdx,ejs
See related https://github.com/remy/nodemon/commit/f7816e445b61e77dd57d5c9ccf5fa0be4f9b18a7 and https://github.com/remy/nodemon/issues/2083. In NodeJS 20, it's possible to customize loader hooks via both the
--loader
and--import
flags, but nodemon currently only accounts for the--loader
hookExpected behaviour
When the
--import
NODE_OPTIONS flag is present, ts-node should not be the default program to execute.ts
and.tsx
files.Actual behaviour
When the
--import
NODE_OPTIONS flag is present, ts-node is the default program to execute.ts
and.tsx
files. Note that this can be worked around by creating a nodemon.json file with the following:Steps to reproduce
.register.mjs
file that uses https://github.com/node-loader/node-loader-babel to compile typescript filesregister("@node-loader/babel", import.meta.url);
Note the error that occurs: