-
Notifications
You must be signed in to change notification settings - Fork 536
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
Update "exports"
to use the correct conditions
#2280
Conversation
Note that this doesn't fix the underlying issues in #2245 - importing `"@primer/react"` using require will still be broken. However, this allows this module to work with nodejs (when using `import`), including next.js.
"exports"
to use the correct conditions
package.json
Outdated
"require": "./lib/index.js", | ||
"default": "./lib-esm/index.js" | ||
"import": "./lib-esm/index.js", |
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.
JSON doesn't allow a trailing comma.
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.
Ah, the danger of trusting myself with GitHub's web editor.
Thanks, I'll get that sorted.
I like this change. It makes the exports more specific to the environment. Happy to merge when CI passes. |
|
I think this does need to result in a release of this package, so I guess we do need a changeset. I don't believe this package's API includes it being imported matching neither of given conditions, so I don't believe this is to be a breaking change. Although I don't think there's any harm in marking this as a breaking change to be safe. I'll be happy to update either way, but I'm also happy for someone else to add the changeset once a consensus is reached. |
@DJMcNab - Do you think removing the "default" option bite some consumer in some way or cause a regression? All implementations will fall in either "require" or "import" right? |
No, I don't believe it will cause a regression. Any JavaScript runtime will match one of the two conditions, so it would have to be a non JavaScript consumer. And I can't think of a single possible case where it would be needed, since this is a JavaScript library. |
I was finally able to get a local development version of this working - I had been having issues with virtualisation, so couldn't actually build this locally until I got that sorted. We appear to be running into vercel/next.js#37419 now. I could resolve that locally by setting this module to However, after this I ran into another issue, where webpack dislikes the dynamism in styled-components. (this appears to be styled-components/styled-components#3601 ) Overall, I'm a bit out of my depth here I'm afraid. Surprisingly, webpack seems to either have no escape hatch for dynamic fields on the default export, or has extremely poor discoverability for that escape hatch. It appears that setting One other thing I did find is that in a project without this PR, just importing the specific files directly works. e.g. import BaseStyles from "@primer/react/lib-esm/BaseStyles"; Note that it needs to be |
From the npm docs:
At the moment,
node
environments unconditionally use therequire
module type inlib
. However, this module type is broken because of #2245. This change allows using the ES modules version for node environments instead, when specified usingimport
.Note that this doesn't fix the issue causing #2245 - importing
"@primer/react"
using require will still be broken. However, this does allow this module to work with nodejs (when usingimport
), including next.js.Merge checklist
I'm not sure any of these are applicable, but I've left them pending further guidance.
Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.