Closed moranbw closed 2 years ago
No, not yet. I think this falls under maybe
territory.
If you run tsm index.ts
on its own in your example, you'll see an ERR_UNSUPPORTED_DIR_IMPORT
error. This comes from Node directly because ESM itself doesn't allow directory imports as it doesn't include CommonJS's auto-index.js
resolution logic.
It works in your ts-node
configuration because you're effectively setting moduleResolution: "node"
, which is telling TS to specifically opt into Node's (classical) resolution behavior.
After looking into my configuration...I wasn't just "effectively setting moduleResolution: "node"
...I actually explicitly had it set in my tsconfig.json
😂
Thank you for the clarification!
I have a directory with a few files that I import into an
index.ts
file. I then import from the directory throughout my code (just feels clean). So something like this inindex.ts
.Then used like this in other places in my project:
import { request1, request2, request3 } from './requests';
To get this to work in
ts-node
I need to run like this:node --experimental-specifier-resolution=node --loader ts-node/esm src/main.ts
I believe
--experimental-specifier-resolution=node
is the key part here. I've been trying something similar withtsm
but no luck yet. I've been getting anERR_MODULE_NOT_FOUND
error when trying to import from./requests
.I'm probably just missing something simple, so my apologies if that's the case! Thanks in advance!