expose-loader works in Chrome but not FireFox?
See original GitHub issueHi there!
After some issues with upgrading from 0.7.5 to 2.0.0 everything where fine with expose-loader thanks to @alexander-akait (Issue#129), until we tested in Firefox and we got several errors.
First off these ones works in both FF(Version 88) and Chrome(Version 89.0.4389.128):
import "expose-loader?exposes=React!react";
import "expose-loader?exposes=ReactDOM!react-dom";
import "expose-loader?exposes=moment!moment";
import "expose-loader?exposes=Tours!./tours.js";
Then we have several entrys like this:
entry: {
bla: ["./bla"],
bla_app: ["./bla_app"],
bla2: ["@babel/polyfill", "./bla2"],
bla3: ["./bla3"],
bla4: ["./bla4"],
bla_5: ["@babel/polyfill", "./SinglePage/bla_5.js"],
bla_6: ["@babel/polyfill", "./SinglePage/bla_6.js"],
},
each entry has its own set of react components that we need to expose to our Razors views to be rendered:
import "expose-loader?exposes=Components!./bla_index.js";
This works without problem in chrome, but fails in FF:
Uncaught Error: [exposes-loader] The "Components" value exists in the global scope, it may not be safe to overwrite it, use the "override" option
and every component from bla_index.js that should be renderd gets undefined
.
React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
If I add this to webpack:
{
test: require.resolve("./App/bla_index.js"),
loader: "expose-loader",
options: {
exposes: {
globalName: "Components",
override: true,
},
},
},
For every file that has its own set of components, this results in 5 of these.
Then I can change the import to:
import "./bla_index.js";
I can even leave it:
import "expose-loader?exposes=Components!./bla_index.js";
Now both FF and Chrome works, if I take away the import completely both of them stop working.
What’s in play here? What is it I’m misunderstand?
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Well I’m not going to bother you more with this “issue”, thanks for the discussion. Awesome help like always 😀! Keep up your awesome work ppl! ✨
You can write
console.log(code)
https://github.com/webpack-contrib/expose-loader/blob/master/src/index.js#L100 and you will see it