-
Notifications
You must be signed in to change notification settings - Fork 26.1k
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
Server build prefers main over module in webpack resolve.mainFields #9323
Comments
bam! also ran into that one some days ago and it drove me crazy! maybe there was a problem with some node packages? But i think in a project like next, that runs code isomorphic in server and client, its a bad idea to resolve packages differently, so this has to be changed. Edit: changing it did not solve my issue, though. But something with the webpack config seems to be odd in nextjs |
Indeed, an override not working as expected. With this module.exports = {
webpack: (config, { isServer }) => {
return {
...config,
resolve: {
...config.resolve,
mainFields: isServer ? ['module', 'main'] : ['browser', 'module', 'main'],
},
}
},
}; I believe server builds runs purely on node and use I ended up pointing my |
It's very common that browser-only code is shipped under the We've tried to change this before and it ends up breaking more cases than it fixes. We're going to leave this option as-is. If you really need it overridden, you can manually do it like you mentioned above. |
@Timer, preferring As a side note, even with my workaround, the way next runs the code in server prevents from |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report[?]
Describe the bug
Webpack's default
resolve.mainFields
are:https://webpack.js.org/configuration/resolve/#resolvemainfields
But next's:
https://github.com/zeit/next.js/blob/8e62c9b688aa7a92e339b728237e8c63ec31f1b5/packages/next/build/webpack-config.ts#L219
The server build prefers
main
overmodule
which may lead to unexpected results (for example, when having a package whosemain
points to ES5+CJS source butmodule
points to ESNext+ESM).To Reproduce
Have a package with
module
field that points to a different source thanmain
, in server build it prefers themain
.Expected behavior
Prefer
module
overmain
in server build. Or, remove this setting completely and use webpack's default.The text was updated successfully, but these errors were encountered: