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
Ignore convert-source-map module in browser builds, fixes @babel/core for browsers #10642
Conversation
Since I'd like to see this fixed directly in This function should be extracted to a separate file: This file should have a corresponding browser file which exports a function which throws when called. |
Hm, not sure if this can be fixed only by refactoring
which would still need to reach I guess the ultimate solution would be to browser bundle different Anyway, could we still merge this in meantime as a workaround? Afaik, there is no point to bundle Agreed that this PR doesn't solve the underlying problem but at least if user doesn't care about source maps, |
|
I see. I opened a PR for "browser": {
"fs": false
}, which is the library level version of this mock. Seems like the most pragmatic way forward. (Note: it doesn't help when placed into @babel/core's package.json since it's a different module) |
Thanks! |
Closing this in favour of thlorenz/convert-source-map#68 @tajo Thank you. |
@tajo Could you open a PR to update |
@nicolo-ribaudo there you go: #10667 |
I am using
transformFromAstSync
function from@babel/core
to compile a code in the browser. The issue is that bundler (webpack in my case) eventually reaches the import ofconvert-source-map
module which further importsfs
and that results in an error since thefs
module is not present in the browser environment.There a few workarounds / solutions:
@babel/core
soconvert-source-map
is not imported anymore (it's needed only when dealing with sourceMaps)config.node = { fs: 'empty' }
but that adds a lot of friction on the consumer sidebrowser
field in the package.json, so we can use it to ignore theconvert-source-map
importThis PR uses the browser field since it doesn't require any code modifications.
(I was also trying to fork
@babel/core
in meantime but the problem is that every single preset (plugin) imports@babel/core
, so I would have to fork the whole plugin ecosystem which is not feasible.)