-
Notifications
You must be signed in to change notification settings - Fork 2k
switch to esm-only with development condition enabling dev-instanceOf-check #4437
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
base: next
Are you sure you want to change the base?
Conversation
@@ -12,6 +12,27 @@ import { Callout } from 'nextra/components' | |||
|
|||
# Breaking changes | |||
|
|||
## `graphql-js` === ESM-only secondary to improved `require(esm)` support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what it's worth, I do think this will hinder adoption due to popular testing libraries like Jest still having pretty terrible support for using ESM-only modules even when Node and TypeScript are in better shape. While I think graphql-js should go here eventually, it will be disappointing if 3+ years worth of incremental improvements are made inaccessible to users who don't want to fight with their test tooling. I think it would be better to get out a GraphQL v17 that has the huge number of small improvements (but no major changes to the build system, implementation of dev mode, etc) and then rapidly release a GraphQL v18 that ONLY has these "build level" changes, so that users can separate their "application-level" migration from their "build system" migration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The underlying motivation is that require-esm supposedly “just works” in the latest versions of Node, so that our users using Jest would not be impacted.
I hope to push another alpha to allow the broader community to experiment with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I encourage you to try it out yourself. I tried making a simple package (@as-integrations/express4
) ESM-only and found that it worked great when run directly from a Node CJS project but that trying to get it to work with Jest (while the project was still CJS-based) was hopeless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, maybe I could work from a project you are getting errors with.
I tried to set up a greenfield project with jest + babel and/or ts-jest and everything was fine testing wise even prior to versions of node supporting require(esm) because the transpilation fixed everything. I am sure I am doing something wrong. Presumably people have other settings that limit transpilation of node_modules? although i did basically just follow the recommended defaults?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@glasser similar demonstration in apollo-server for a canary taken from this PR:
apollographql/apollo-server#8082
These changes seem pretty straight-forward => once we are comfortable dropping support for the earlier versions of Node.
Some esm package with different setups might be trickier. For example, I looked randomly at @sindresorhus/is
and that required bumping the module
and moduleResolution
to node16
from node
, for reasons that I have yet figured out. Maybe it has to do with the types
condition on exports
in that package? Not sure. In any case, our package setup seems more flexible.
Would love to get additional feedback on when we do this. At first I wanted to push for v17, but with the points @glasser was making, I became fearful that despite require(esm)
support, we might have to hold off even longer. Considering how basic these changes are for our library, I am wondering if we can go back to including in v17, and would push for that, but barring that, I am certainly comfortable with the suggestion above of releasing v17 without this change but prioritizing a v18 with this change.
2e8d3a3
to
7ed7d05
Compare
7ed7d05
to
458bdf8
Compare
85fff1d
to
8e9e67b
Compare
Co-Authored-By: Yaacov Rydzinski <yaacovCR@gmail.com>
e8008ad
to
42896f2
Compare
42896f2
to
bfeb14b
Compare
Takes the no-op trick from #4426, but responding in a small way to feedback from @glasser in terms of discoverability, uses the development condition to enable this behavior by default.
The development condition must be passed to node via a flag
node --conditions=development ...
and is not set automatically fromNODE_ENV=development
.