Closed nathansom closed 5 months ago
I have this exact problem. So far I've found this is a problem when using nx's babel preset. If I switch to @babel/env, the browserslist is respected. But then I'm not sure what else does the nx's preset do and if I can switch away from it.
The problem with the nx's preset is, when babel gets to handle the polyfills, it gets some weird default list of targets which includes some old versions of browsers, and mobile browsers too. The correct list of targets is there too in a "context" var, but isn't used for some reason.
Please fix.
Here are some of my observations.
This seems to be somehow related to the isModern
setting which, when set to true, sets targets
to { esmodules: 'intersect' }
.
https://github.com/nrwl/nx/blob/b6d2f88e8202373188fafcb679e230342c30e2d1/packages/js/babel.ts#L63
The isModern
setting seems to be hardcoded to true
everywhere (I'm confused - does this mean we can't build against non-modern browsers now?).
Now I'm not sure what is the esmodules: 'intersect'
setting meant to do. I guess it means the babel should take the targets calculated according to the browserslist
and intersect it with targets which allow es modules. The problem is, if this is set, babel actually doesn't pick up the browserslist and it just uses the default list of targets for es modules, which contains rather old versions of many browsers, including mobile ones.
It could be because here in babel https://github.com/babel/babel/blob/5ebab544af2f1c6fc6abdaae6f4e5426975c9a16/packages/babel-helper-compilation-targets/src/index.ts#L178
the configPath
is the workspace root, not the root of the application, so babel will not find the browserslist
there.
Upon further debugging I noticed that here
the dirname
variable does contain the application root dir, but as it is passed further, it is completely ignored (the third param is not used) here
and here
But this is how it is for a long time already in babel, so I really don't know if this is a bug or not. All I know is that if I use that third param to set configPath
, the browserslist
config gets picked and everything works as it should.
I'd appreciate if someone more capable than me looked into this and said if this is a bug in nx or if it is a bug in babel which I could file.
Please forgive me, just to raise attention, let me tag you @FrozenPandaz since this looks (to me) like quite a big deal.
Thanks for sharing @ziacik! I actually have resolved this issue a while ago by removing @babel/plugin-transform-runtime from the plugins array. Browserlist isn't even needed anymore and the bundled JS passed the validator that really hates IE.
Still, I am hoping that there will be a more detailed documentation for Nx's presets for what configurations that are already included.
this does appear to be an issue with Babel itself.
There are two similar issues reported on their repo currently: https://github.com/babel/babel/issues/9429 and https://github.com/babel/babel/issues/7758
Where browserslist
is not being respected correctly based on where it is defined.
As such, I'm going to close this issue.
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.
Current Behavior
I used @nx/webpack:webpack executor to bundle TypeScript files for production and I set custom Browserslist config in
.browserslistrc
withHowever, the bundled file still shows traces of IE support and reference to ActiveXObject object, which is a critical issue for using my production code on Microsoft Power Platform as the platform's solution checker does not allow reference to browser specific API, especially the dead one.
Expected Behavior
IE support is totally dropped since I specified
not dead
andnot ie 11
in the brwoserslist config. No reference to ActiveXObject or any other IE-specific API. The Microsoft Power Platform's solution validator should not detect an attempt to access or reference an API specific to unsupported browser.GitHub Repo
No response
Steps to Reproduce
src/lib
that export an object containing a function:export { obj: { a: funcA} };
webpack.common.js
:webpack.prod.js
:module.exports = composePlugins(withNx(), (config, { options, context }) => merge(config, common, { mode: "production", devtool: false }) );
Create tsconfig.lib.json
Create
.browserslistrc
at the root of projectbuild-prod
taskNx Report
Failure Logs
No response
Package Manager Version
No response
Operating System
Additional Information
No response