Replies: 5 comments 3 replies
-
implies to me that you compile your typescript to commonjs? would it be possible for you to compile to ESM instead? |
Beta Was this translation helpful? Give feedback.
-
Compile to ESM is my goal, but I'm not sure I'm doing it right. in my "module": "NodeNext"
"moduleResolution": "node"
"esModuleInterop": true while in my |
Beta Was this translation helpful? Give feedback.
-
Actually after tinkering a bit I discovered I was wrong: there is the same problem using the named imports. So now I'm stuck again, and I can't understand how to develop a pure ESM module in typescript :-| |
Beta Was this translation helpful? Give feedback.
-
I have the same problem, has anyone solved it? |
Beta Was this translation helpful? Give feedback.
-
I solved it by using node 18+ that has integrated fetch :-) |
Beta Was this translation helpful? Give feedback.
-
I'm developing a new project so I can start from scratch using latest standards, so I'm using latest 16.x node, latest typescript (4.8.2), and trying to develop an ESM library.
The problem I have is that I can't import the default export, while everything works fine for the named imports.
So for example this works fine:
while this code:
gives this error:
Is it possible for you do avoid exporting the default and simply do a named export for "fetch"?
Or maybe both, to have better compatibility with cjs?
I'm no export on ESM modules but I think that a trivial fix would be to avoid exporting the definition of the function this way:
and define the function and export it in two different places like this:
Beta Was this translation helpful? Give feedback.
All reactions