Skip to content
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

Package exports mean node version is always used with Webpack 5 #145

Closed
gjvoosten opened this issue Feb 3, 2021 · 1 comment · Fixed by #146
Closed

Package exports mean node version is always used with Webpack 5 #145

gjvoosten opened this issue Feb 3, 2021 · 1 comment · Fixed by #146

Comments

@gjvoosten
Copy link

Describe the bug

The current package.json specifies: https://github.com/JSONPath-Plus/JSONPath/blob/v5.0.2/package.json#L7-L10
which, if I read https://webpack.js.org/guides/package-exports/ correctly, mean the node version is always imported, even in browser mode.

We noticed this change in behaviour when our JSONPath queries were suddenly taking much longer to run after upgrading from v4.0.0 to v5.0.2. A query that would take < 3ms under v4.0.0 was suddenly taking > 100ms under v5.0.2. Replacing index-node-esm.mjs with index-browser-esm.js would bring the performance back to normal.

@brettz9
Copy link
Collaborator

brettz9 commented Feb 3, 2021

From the PR at #146 (comment)

Hmm... I've added a comment at webpack/webpack#11597 (comment) , as it looks to me that bundlers should not be using type for interpretation of non-Node fields. There is a workaround there that may work for now without our changing the code, as I really think we should be able to use ".js" with browser ESM while using type: commonjs for Node. If we don't hear back in some time, let's file a new Webpack issue.

Also, when we may be able to revisit this, per the end of https://nodejs.org/api/packages.html#packages_conditional_exports :

...using "node" and "default" condition branches is usually preferable to using "node" and "browser" condition branches.

gjvoosten pushed a commit to gjvoosten/JSONPath that referenced this issue Feb 4, 2021
@gjvoosten gjvoosten changed the title Package exports mean node version is always used Package exports mean node version is always used with Webpack 5 Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants