ESM Support #693
rostislav-simonik
started this conversation in
General
ESM Support
#693
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Short intro
When I took over the maintenance of nexus-prisma, some work was already done to support esm build. I assumed it works, and when I cut a new release the esm build was exposed to esm projects. What introduced a few issues
Some discussion before
Status
esm support was started merely finished. It requires much more work to do. It's not hard to do. Over the weekend I almost converted the whole package to support esm, but it end up creating a polymorphic project supporting both commonjs and esm.
Changes required to do
1. Fixing directory and relative imports
ESM modules don't support folder imports and relative imports without specifying file extensions.
from
to
2. Supporting __dirname
__dirname
__filename
are not supported by esm modules. There is an alternative usingimport.meta.url
.So we would need to have something like this in each file that requires __dirname:
3. Imports of commonjs packages with default export
If we are importing commonjs default export, then it needs to be treated differently in commonjs and esm,
in commonjs
in esm
we could end up with the following snippet
4. Some more
I haven't finished but could be more challenges to overcome
Do we need esm build at this moment?
I think It's not needed, commonjs version can still be used in esm project. And I think it would be good if
nexus
,prisma
will support first, and then we can add support for nexus-prismaWhat's next
I will release a patch to remove esm build #696, so it's not present in the published version. I'll also include e2e test to test commonjs version of nexus-prisma in esm projects.
Feel free to write your thoughts about this.
Beta Was this translation helpful? Give feedback.
All reactions