react-shade icon indicating copy to clipboard operation
react-shade copied to clipboard

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

Open o-t-w opened this issue 7 years ago • 11 comments

I am getting the following error when attempting to use the latest release (0.4.0)

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

I installed with Yarn into a basic create-react-app project.

I tried:

import {styled} from "react-shade";

const P = styled("p", {
	":host": {
	color: "green",
	textTransform: "uppercase"
}
});

export {P};

and:

const P = styled({
	":host": {
	color: "green",
	textTransform: "uppercase"
}
}, {name: "p"});

o-t-w avatar Jan 27 '19 00:01 o-t-w

Interesting. I'll have a look.

treshugart avatar Jan 27 '19 21:01 treshugart

I just noticed I updated the docs in master but haven't released the new api for styled yet. This is probably not your issue, but just FYI.

I can't reproduce this yet, but will try again a bit later.

treshugart avatar Jan 27 '19 23:01 treshugart

@o-t-w, just add this to your webpack config rules:

      {
        type: 'javascript/auto',
        test: /\.mjs$/,
        use: []
      }

avele avatar May 02 '19 03:05 avele

@o-t-w, did @avele's solution work for you?

treshugart avatar May 26 '19 23:05 treshugart

@treshugart - Same error here. Using typescript. I've no idea what generates this error, but @avele 's suggestion to add that snippet to webpack's config did work for me.

tobyhinloopen avatar Jun 21 '19 11:06 tobyhinloopen

I think this is likely an issue where TypeScript doesn't support .mjs files by default. Closing for now unless we can pinpoint this as being an issue with react-shade itself. Thanks again for the fix @avele!

treshugart avatar Mar 06 '20 18:03 treshugart

Another work around for this is importing react-shade/dist/index.js directly. It seems microbundle outputs an .mjs file for module and TypeScript prefers that, but doesn't support .mjs. Not sure yet if we can workaround this with microbundle.

treshugart avatar Mar 28 '20 17:03 treshugart

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

vaniadimova avatar Oct 27 '21 19:10 vaniadimova

any updates , faced on with the same issue

iamakiraa avatar Oct 29 '21 15:10 iamakiraa

@vaniadimova @iamakiraa did you try importing react-shade/dist/index.js directly, or did you try @avele's solution?

treshugart avatar Oct 29 '21 17:10 treshugart

@vaniadimova @iamakiraa did you try importing react-shade/dist/index.js directly, or did you try @avele's solution?

@avele's solution helped, so I used react ts app, I ejected app, and modified web pack config.

iamakiraa avatar Nov 08 '21 17:11 iamakiraa