With output.environment.module, packaged dependency gets incorrect reference to external dependency
See original GitHub issueBug report
What is the current behavior?
I’m building a react component library, so I declare react and react-dom as externals
. I’m using webpack to build our library as a module, with experiments.outputModule = true
, output.environment.module = true
, and output.library.type = 'module'
.
I’m using a library that also declares react
as an external dependency.
When I do my build:
- In the compiled code, we end up getting a reference to
react
asexternal_react_
- my code’s calls to
React.createContext
get compiled correctly asexternal_react_.createContext()
- my dependency’s calls to
React.createContext
get compiled incorrectly asexternal_react_["default"].createContext()
This results in a hard crash in consumers of my library, because external_react_["default"]
is undefined
and then external_react_["default"].createContext()
throws.
If the current behavior is a bug, please provide the steps to reproduce.
reproduction case: https://github.com/MustafaHaddara/webpack-external-repro-case
What is the expected behavior?
My dependency’s calls to React.createContext
should get compiled as external_react_.createContext()
Other relevant information: webpack version: 5.65.0 Node.js version: 14.16.0, also reproduced with 16.7.0 Operating System: Additional tools:
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
ok, that makes sense.
thanks for your help!
I tested it using https://github.com/MustafaHaddara/webpack-external-repro-case/blob/main/es/index.js, just run this in browser or using
Node.js
(document will be undefined)What is webpack version in CRA? Please run
npm ls webpack