New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error require of ES Module not supported #82
Comments
Hey @sindresorhus I dont know how this helps. I dont use any This is reproducible using a blank NestJS project:
|
Did you read the How can I make my TypeScript project output ESM section? |
Yes I did read it twice. It happens even in a blank new NestJS project as shown above. |
It is "weird" that I have more than 200 packages installed but serialize-error is the only one producing this error |
After re-reading your post and seeing this...
...and assuming you've already read this, I suggest you open an issue on ts-node or comment on this one |
Another idea: try to install and use another of Sindre's small ESM packages, such as alpha-sort, and see if they work. Maybe Sindre made a mistake when moving to ESM in this specific package? Since both packages are small, perhaps you can spot the issue yourself and send a PR. |
I am having the same issue. Did you find a way to solve this? Thanks. |
Actually I stayed on 8.1. We have 5+ Nest / TypeScript projects with hundreds of dependencies and this is the only one making problems and as I wrote above it is easy to reproduce. If you find anything please post it here, thanks! |
I've rolled back to 8.1 as well. I have also looked at the v11 repo and have started a process of converting it to my own module, possibly in Typescript. If I get any further along with that and have something functional, I will give you a shout. Given that the package is not updated very often, it might just be preferable to maintain my own repo as a copy of this one and check back here for updates from time to time. |
I have also rolled back to: FWIW running: |
@sindresorhus could you please reopen as so many people are reporting the same issue? |
I fussed around with it more and the following statement works for me instead of the normal imports in 11.x for serialize-error const { serializeError } = await (eval(`import('serialize-error')`) as Promise<
typeof import('serialize-error')
>); The more I've dug into this the more I'm leaning toward this not being a library specific issue. Rather its an issue within the JS community about handling ESM modules appropriately. I got the idea for that bit of code from the following SO: https://stackoverflow.com/questions/70545129/compile-a-package-that-depends-on-esm-only-library-into-a-commonjs-package While not elegant I have a feeling until TS-Node offers support for transpiling to ESM this won't be easily solved. Nor should we expect the library maintainer to fix it, since its not an issue with the library, rather the transpilation process from TS -> JS for ESM modules. |
@twosdai But if you're right, why would this be happening to Also, why use |
@papb For as to why this module, in this place, in the specific point in time, localized in this specific repo. *shrug. Its an ESM module import issue for transpiling, I'm not sure if any of the other repo's that I've installed are actually using ESM modules and this is just the first one in a long line of breaking dependencies, or if there is a specific bug present in ts-node for transpilation. As far as I can see between the diff of the |
Like almost every sindresorhus/* package lately, this one also does not work with jest... Probably same problem. |
@twosdai Is there any issue open in TS for this? |
@papb TypeStrong/ts-node#1007 EDIT: |
Having the same problem. "dependencies": { |
@Torrichel Did you try
for importing instead? just in case you want to keep the new version. |
oooh typescript. I tried this solution, then of course I got wrapped it in an async IIFE and got
|
Since 9.x (I also tried 10.x and 11.x) when importing serialize-error:
I get the following error:
It works when building with
tsc
but not when starting withts-node
. Any idea what this could be? I dont find anyrequire()
somewhere...The text was updated successfully, but these errors were encountered: