babel icon indicating copy to clipboard operation
babel copied to clipboard

[Bug]: Bundling @babel/standalone by webpack emits warnings

Open joshuahhh opened this issue 2 years ago • 4 comments

💻

  • [ ] Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

import '@babel/standalone';

Configuration file name

No response

Configuration

N/A

Current and expected behavior

Current behavior: When bundling a project with Webpack which includes code that imports '@babel/standalone', Webpack reports:

WARNING in ./node_modules/@babel/standalone/babel.js 308:11-32 Critical dependency: the request of a dependency is an expression @ ./src/index.js 9:0-27

WARNING in ./node_modules/@babel/standalone/babel.js 346:11-24 Critical dependency: the request of a dependency is an expression @ ./src/index.js 9:0-27

I think this is due to commonjsRequire's use of require(path).

Environment

Tested in a fresh create-react-app environment, as well as a more minimal Webpack environment.

Possible solution

Given that @babel/standalone is intended for use in a browser environment, I wonder why it includes bare require() calls. Perhaps these parts could be excluded from this build?

Additional context

Please let me know if there's anything else I can do to help. Thanks a bunch!

joshuahhh avatar Feb 23 '22 21:02 joshuahhh

Hey @joshuahhh! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

babel-bot avatar Feb 23 '22 21:02 babel-bot

This is https://github.com/rollup/plugins/issues/1085.

Update: it is not. The require in commonjsRequire is the fallback in case we fail to bundle the dynamic required libraries used in @babel/standalone, which should be a bug. commonjsRequire is in rollup commonjs helper so we can't simply remove it. For now you may ignore such warnings.

JLHwung avatar Feb 28 '22 14:02 JLHwung

@JLHwung hello, is this bug has been fixed yet? I find the same question at version @babel/[email protected]

SxxPorsche avatar Jul 22 '22 06:07 SxxPorsche

@SxxPorsche I simply searched in the file content and didn't find anything similar to require(path), can you provide a reproducible repo?

liuxingbaoyu avatar Jul 25 '22 17:07 liuxingbaoyu

Still facing this issue in 7.21.2.

radhasatam avatar Mar 08 '23 12:03 radhasatam

@radhasatam Can you provide a reproducible repo?

liuxingbaoyu avatar Mar 09 '23 07:03 liuxingbaoyu

Still facing this issue in 7.21.4. See: https://github.com/Mity1299/babel-standalone-webpack-bug run npm run build will see the error: Critical dependency: the request of a dependency is an expression

superoery avatar Apr 04 '23 08:04 superoery

Thanks, I can reproduce the problem. Opened an issue https://github.com/rollup/plugins/issues/1472.

liuxingbaoyu avatar Apr 04 '23 19:04 liuxingbaoyu

That issue https://github.com/rollup/plugins/issues/1472 was closed due to inactivity ;( Is there another way out?

tomitrescak avatar Jun 20 '23 06:06 tomitrescak

It would be awesome if someone could work on a rollup PR to fix that issue :)

nicolo-ribaudo avatar Jun 26 '23 06:06 nicolo-ribaudo

I'll try to do it in a few days. :) (previously I wasn't sure if this should open a rollup PR)

liuxingbaoyu avatar Jun 26 '23 06:06 liuxingbaoyu