Dynamic import()
with "module": "commonjs"
#1290
-
With Here are a few options to do that: Option one: use
|
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 13 replies
-
This is a recipe for solving a common problem. We'll try to keep it up-to-date. If it is confusing, we can update it based on questions posted here. |
Beta Was this translation helpful? Give feedback.
-
This might be due to my inexperience with Typescript but this seems to be the challenge:
I couldn't figure out a way to force Typescript not to compile a file that is included by a TS file. Even if it's a |
Beta Was this translation helpful? Give feedback.
-
Code seems invalid:
Changed to but getting:
Added
Changed to
Note: tsconfig:
Trial #2 Changed to
can't find the file now. Enabled js in tsconfig:
Back to square 1. - This is where I started. I guess this can't be used anymore. It's really insane how hard it to use ESM module with ts-node. Wasted hours trying random stuff... and still can't find a solution. |
Beta Was this translation helpful? Give feedback.
-
with my own package I can just import types and real fn in a cleaner way:
The benefit of esm is minimal, but having to change ton of stuff is too expensive. I rather drop the library or re-implement myself at this point. |
Beta Was this translation helpful? Give feedback.
-
Use moduleResolution: 'node16' with module: 'commonjs' in tsconfig.json, ts will keep all the dynamic import statements as is. But ts-node will panic at this situation. |
Beta Was this translation helpful? Give feedback.
-
This one helped me fix my problem in a case where external packages in a project are limited. Thanks a lot 👍 |
Beta Was this translation helpful? Give feedback.
-
Note for "Option two: copy-paste this helper function" that on Windows we need to use |
Beta Was this translation helpful? Give feedback.
This is a recipe for solving a common problem. We'll try to keep it up-to-date. If it is confusing, we can update it based on questions posted here.