TypeScript compilation fails with "TS1479: The current file is a CommonJS module" #2778
-
Hi! First time using
The fixTo fix, I removed I got that idea from #1699 (comment) which explores a related TypeScript compilation error - but that was fixed in #1721 in July 2022. Does anyone know why I am getting this error, and if there's another way to resolve it? My setupI'm adding this to a Symfony 6.2 codebase, which uses webpack-encore, which is a light wrapper around When running
In my "module": "ESNext",
"moduleResolution": "NodeNext",
"resolveJsonModule": true, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
I'm experiencing the same issue with the @headlessui/react library. A potential workaround is to follow the instructions in the warning to dynamically import the components. Instead of importing at the top of the file like this:
Try async/awaiting the import within the component itself:
This gets rid of the warning for me. I haven't been able to test it at runtime yet (in the middle of a big refactor), and I have no idea if this is an ideal solution, but it beats having to edit the headlessui package itself. |
Beta Was this translation helpful? Give feedback.
-
Hello, I'm not sure about this, but you can use "moduleResolution" : "Bundler" instead of "NodeNext" with Typescript 5. Good luck |
Beta Was this translation helpful? Give feedback.
-
One of the maintainers realised that this was actually not working properly, and has a fix which will be in the next release. See #2838 (comment) |
Beta Was this translation helpful? Give feedback.
One of the maintainers realised that this was actually not working properly, and has a fix which will be in the next release. See #2838 (comment)