-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Uncaught SyntaxError: The requested module '/MyComponent.mjs' does not provide an export named 'default' #8318
Comments
webpack doesn't support that yet. Best avoid bundling and only transpile the modules with babel. If you want to bundle, you can use rollup which supports this. |
Do you have plan to support this in the future? |
Not in short term, but we plan to add it eventually. |
What are the difficulties? If it is simple, I want to contribute it. |
It's not that simple. We need to be able to remove the runtime first. For this some refactoring is needed that is planned for webpack 5. |
After a research, I have just found that umd and esm cannot coexist in the same and single bundle. Am I correct? |
webpack bundles can combine modules of any format: ESM, AMD, CJS, UMD Related to this issue: When compiling into a ESM the entry module also need to be ESM. Referenced modules can be of any format, but must be |
I want to make sure I understand your answer.
You are saying before the webpack bundling, we can import or require from any format and webpack must understand any kind of import or require
If I use webpack to output a bundle in ESM format, the consumer side can only use native ESM import. If my understanding is correct, this means at the beginning we have to decide either ESM or non ESM (CJS, AMD, UMD...) target. If it is ESM world, webpack does not need to include webpackBootstrap
You are saying not only creating the |
I'm referring only the the entry module. That's the first module in the graph. All other modules can be in any format. (But when using any non-ESM format we need to add a small module runtime to the bundle. It's not the same as webpackBootstrap, but similar.) Javascript loaded via
That's already possible. The missing part is an alternative output format which allows to Note that it's already possible to run bundles with
You don't have to decide that. You can create two bundles, one in ESM and one in UMD. They need to be consumed differently, but can contain the same code. |
I want to make sure if my direction is same as your expectation based on your reply For example, I have two entries A.jsx and B.jsx. Currently, webpack will output 3 js files and they are A.js, B.js and common.js. common.js is the shared code for A.jsx and B.jsx. In order to support native export, webpack will output 5 files which includes previous 3 js files I have mentioned. The rest of files are A.mjs and B.mjs. These two files will contain some webpackBootstrap code to load the module and then export it in es6 syntax. Am I correct? |
No it would still output 3 files A.js, B.js, common.js A.js and B.js would You are free to change the extension to .mjs but browser don't care about that anyway. |
I really appreciate your patient for the explanation. I will have a try |
Currently, the UMD output (template webpackBootstrap code) is purely in es5 syntax. If we put the es6 export in the same file, it may break in runtime on certain environment For example, I use webpack to output a lib for node and browser to run. Node is partially support es6 module and IE does not support it. |
It's not possible to put ESM exports into UMD. Your file is either UMD or ESM. |
So what is the workaround for this, can you be more specific? I'm new to webpack, so "rollup" doesn't say anything to me. |
This issue had no activity for at least half a year. It's subject to automatic issue closing if there is no activity in the next 15 days. |
Issue was closed because of inactivity. If you think this is still a valid issue, please file a new issue with additional information. |
Have been reading the comments here but didn't got an clear statement of what should I do in order to resolve this case: Tried to run a script that loads my app, and got into this error:
|
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
I have a React component
MyComponent.jsx
and I try to use webpack to output the component in es6 format for people to consume without the transpiler.This is
webpack.config.js
for webpack to output jswhen I use index.html to consume /MyComponent.mjs, it gives
Uncaught SyntaxError: The requested module '/MyComponent.mjs' does not provide an export named 'default'
Here is the html
If the current behavior is a bug, please provide the steps to reproduce.
This error message is in the browser console
What is the expected behavior?
Uncaught SyntaxError: The requested module '/MyComponent.mjs' does not provide an export named 'default'
should not throwIf this is a feature request, what is motivation or use case for changing the behavior?
Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.
The text was updated successfully, but these errors were encountered: