Microbundle: Can't import the named export 'xxx' from non EcmaScript module (only default export is available)

Created on 21 Jun 2019  路  7Comments  路  Source: developit/microbundle

I'm building with microbundle -ts --jsx react

And import like this:

import { DrawComponent } from 'encompass-ecs';
/** Marker component to indicate an entity is a candidate to be used in React */
export class ReactSyncComponent extends DrawComponent {}

The build is fine. But when I import my bundled lib, I got:

Failed to compile.

./node_modules/react-encompass-ecs/dist/react-encompass-ecs.mjs
Can't import the named export 'DrawComponent' from non EcmaScript module (only default export is available)

Where react-encompass-ecs.mjs looks like this:

import{DrawComponent as f,Renders as a,EntityRenderer as s,GeneralRenderer as l,EntityChecker as m}from"encompass-ecs";

Most helpful comment

Might be worth reverting Microbundle itself to produce .module.js instead of .mjs. This is painful.

All 7 comments

I've also run into this and am working around it by removing mjs from the output.

This may be a related thread:
https://github.com/apollographql/react-apollo/issues/1737

yeah it's a problem with webpack sadly, we had to revert back in preact as well

Might be worth reverting Microbundle itself to produce .module.js instead of .mjs. This is painful.

I assume that going forward the modern format is supposed to fix this?

Is there anything I can do to move the @next version forward?

Any update on this?

Rollup's commonJS plugin offers namedExports option

Actually this is super easy to fix.

Just rename your module field and don't use the *.mjs extension.

I fixed it by renaming module field from dist/index.mjs to dist/index.esm.js.
Reason webpack treat's *.mjs modules very strictly in regard to named imports of commonJS modules.

oh wow, I thought we had updated that in the readme

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MarkLyck picture MarkLyck  路  4Comments

kuldeepkeshwar picture kuldeepkeshwar  路  4Comments

belozer picture belozer  路  3Comments

developerdizzle picture developerdizzle  路  5Comments

dmitrykurmanov picture dmitrykurmanov  路  3Comments