-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Can't import the named export 'Component' from non EcmaScript module (only default export is available) #1395
Comments
CRA doesn't support |
This is a huge problem for most users, and increases the time needed to configure // config-overrides.js
const { override } = require("customize-cra");
const supportMjs = () => (webpackConfig) => {
webpackConfig.module.rules.push({
test: /\.mjs$/,
include: /node_modules/,
type: "javascript/auto",
});
return webpackConfig;
};
module.exports = override(
supportMjs()
); |
Same issue here, not using webpack. And we need to roll back to 3.0.0 to fix this problem. |
I am having the same issue using babel/webpack. When debugging, I noticed a couple issues with the built code, spot checked using message.mjs
|
@lc-stevenzhang what's ur setup? |
We use create-react-app + circle-ci. With latest version of React and npm, running on MacOs Mojave 10.14.6. And got exact same build error as @danilofuchs . |
Ah ok unfortunately CRA chose not to support mjs because of jest. A lot of
libs are in the same camp as we are (graphql for example).
…On Tue, Aug 6, 2019 at 7:35 PM Steven Zhang ***@***.***> wrote:
@lc-stevenzhang </~https://github.com/lc-stevenzhang> what's ur setup?
@polson136 </~https://github.com/polson136> does formatjs/formatjs#143
(comment)
<#143 (comment)>
not work for u?
We use create-react-app + circle-ci. With latest version of React and npm,
running on MacOs Mojave 10.14.6. And got exact same build error as
@danilofuchs </~https://github.com/danilofuchs> .
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1395>,
or mute the thread
</~https://github.com/notifications/unsubscribe-auth/AABQM34PXTOKFZT6FD3JJX3QDIDDRANCNFSM4IJZQNGQ>
.
|
I'm sure the community for Maybe The base minimum is to document well the steps needed to configure CRA / webpack 4. |
It does work, but the reason why it works is because, as I mentioned in my previous comment, you are using .mjs wrong. The errors we are getting are correct according to the behavior of .mjs as described in the node documentation. But you're really not doing anything special, there are many projects that export both commonjs and esm versions, so no special configuration should be required. (not even the extension part) To name a few: |
Looking at the bundle produced by these projects, they usually export 2 or more folders:
And in |
We used to separate out ESM/CJS dist, but then it broke some other bundling tool. The short answer is that there's no perfect solution for all bundlers (webpack/rollup/fuse-box/parcel/node) along with their transpiler combo (babel/typescript). This project doesn't have enough resources to debug them all unfortunately. So far the current state only breaks CRA (which doesn't allow custom webpack config & that's on them) and I'm fine with that. I want to focus our efforts on new features instead of fighting bundlers. |
May I ask which bundler(s) the old way broke? |
That sentiment is completely understandable, but unfortunately this:
is seriously off the point here. It doesn't much matter that it's technically possible to use |
Why is this package using .mjs, anyway? I have a medium sized project (~50k lines of code) with a lot of dependencies and none of them is using mjs. Quite a lot of them provide ES modules builds, but it's usually named index.es.js or esm.js and it works perfectly fine, also with treeshaking. Don't quite understand the need to use .mjs here. If it's because of Node compatibility I wonder how many people actually use it in Node considering it's named react-intl, unless it's relevant for things like next.js, but I'm not sure here. I don't know what's your goal with this project but if you want people to use it, making it work on CRA without any additional config, like majority of React-related libraries do, should be a very high priority. |
PR’s welcome. As I said I don’t have bandwidth to cross check all the
bundlers & transpilers combo.
…On Thu, Aug 8, 2019 at 4:49 PM Paweł Dąbrowski ***@***.***> wrote:
Why is this package using .mjs, anyway? I have a medium sized project
(~50k lines of code) with a lot of dependencies and none of them is using
mjs. Quite a lot of them provide ES modules builds, but it's usually named
index.es.js or esm.js and it works perfectly fine, also with treeshaking.
Don't quite understand the need to use .mjs here. If it's because of Node
compatibility I wonder how many people actually use it in Node considering
it's named *react*-intl, unless it's relevant for things like next.js,
but I'm not sure here.
I don't know what's your goal with this project but if you want people to
use it, making it work on CRA without any additional config, like majority
of React-related libraries do, should be a very high priority.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1395>,
or mute the thread
</~https://github.com/notifications/unsubscribe-auth/AABQM34XGFIFBMHVFDNWBZLQDSBELANCNFSM4IJZQNGQ>
.
|
I don't either. I'll try to tackle this on Saturday, but my main goal will be making it work on a typical CRA based app without any additional config, hopefully without breaking what you currently have. |
https://codesandbox.io/s/fervent-hypatia-f855r uses vanilla CRA & react-intl & it works so I also don't know what's wrong. I personally don't use CRA so I can't debug. |
Well, and on top of that, is that the way they are implementing .mjs is just straight wrong. It clearly violates the closest thing I could find to a spec: https://nodejs.org/api/esm.html#esm_differences_between_es_modules_and_commonjs |
Fix: revert 5fd070d |
it was attempting to solve importing from the same path & get cjs or esm if supported, e.g |
@longlho I'm not putting the time into opening a PR unless there is a chance that it might be accepted, and right now it's quite clear that we disagree on what the solution should be, and you are the only representative of the project on this thread. Regarding Generally, most people know whether their environment supports ESM or commonjs, so I assume that using subpath imports consistently between commonjs and esm is intended for people using a bundler such as webpack, as well as environments which do not natively support ESM, such as tests or SSR? If you were instead to revert to the 3.0 build system, then people who wanted to do subpath imports could do The other option is to fix the build process so that it correctly follows the .mjs spec by including the file extensions in the import paths and correctly importing commonjs modules. I don't think that is feasible at this time, since there is no tooling available to do that because no one will implement it until the spec is finalized (/~https://github.com/nodejs/modules/blob/master/doc/plan-for-new-modules-implementation.md#phase-3-path-to-stability-removing---experimental-modules-flag). Once the spec is finalized in October and the tooling catches up, then something like this will probably make a lot of sense, and this can be revisited. |
@longlho Thank you. |
It does break not only CRA, but our Gatsby.js typesctipt projects too. Typescript does not support |
@JustFly1984 this was fixed and released yesterday. Please try it out. Thanks! |
if you have imported ======> |
@vue-reactivity/watch use tsup as its bundler, which create .mjs file as the ES module output. But webpack4 do not like .mjs extension which cause tools like create-react-app failed when using meta-ui. Even users can add some trick to let webpack4 bundle .mjs file, the watch function still not working. Refs: 1. facebook/create-react-app#10356 2. formatjs/formatjs#1395 (comment)
This is not working |
@Aadil-Shabir Have you found any solution for that? |
@vue-reactivity/watch use tsup as its bundler, which create .mjs file as the ES module output. But webpack4 do not like .mjs extension which cause tools like create-react-app failed when using meta-ui. Even users can add some trick to let webpack4 bundle .mjs file, the watch function still not working. Refs: 1. facebook/create-react-app#10356 2. formatjs/formatjs#1395 (comment)
To prevent ESM errors for external packages. Kinda explanation: formatjs/formatjs#1395 (comment) (2)
following, facing the same problem |
Framer motion you suck ass!!!! |
Honestly this entire library (framer motion) should be deleted.. it's utterly useless and not to mention the fact impossible to install. It's a joke of a library, and it's a disgrace that they still proudly display their 'work'. |
When using create-react-app with Typescript, I cannot complete a successful build.
Expected behavior
Should build
Current behavior
Does not build
Step to reproduce for BUG REPORT
Your Environment
npm ls react-intl
npm ls react
yarn --version
node --version
The text was updated successfully, but these errors were encountered: