-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
@emotion/styled/base
imports don't work with native ES modules
#2413
Labels
Comments
I'm able to workaround the issue with this Babel config: // babel.config.cjs
// Get the actual path to the ESM module, i.e. `@emotion/styled/base/dist/emotion-styled-base.esm.js`.
const path = require('path');
const emotionPkg = require('@emotion/styled/base/package.json');
const styledBaseImport = [
'@emotion/styled/base/' + path.normalize(emotionPkg.module),
'default',
];
module.exports = {
presets: [
[
'@emotion/babel-preset-css-prop',
{
autoLabel: 'always',
labelFormat: '[local]',
useBuiltIns: false,
throwIfNamespace: true,
importMap: {
'@emotion/styled': {
default: {
canonicalImport: ['@emotion/styled', 'default'],
styledBaseImport,
},
},
},
},
],
]
} |
Ran into the same issue with {
plugins: [
[
'@emotion',
{
importMap: {
'@emotion/styled': {
default: {
canonicalImport: ['@emotion/styled', 'default'],
styledBaseImport: [
'@emotion/styled/base/dist/emotion-styled-base.esm.js',
'default',
],
},
},
},
},
],
],
} |
4 tasks
Ended up writing custom babel transformer to resolve this issue as it appeared while running some tests in a repo.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Current behavior:
I'm trying to use native ECMAScript modules in Node.JS in a project that uses
@emotion/styled
and@emotion/babel-preset-css-prop
.When
@emotion/babel-preset-css-prop
runs it injects an import from@emotion/styled/base
which looks like this:Since this is a directory import, and directory imports only work with CommonJS, it fails with an
ERR_UNSUPPORTED_DIR_IMPORT'
error.To reproduce:
You can reproduce the issue with this Github repository.
The main points are:
@emotion/styled
@emotion/babel-preset-css-prop
and make sure@babel/preset-env
is configured with{modules: false}
node lib/index.js
Expected behavior:
The import works.
Environment information:
react
version: 17.0.2@emotion/react
version: 11.4.0@emotion/styled
version: 11.3.0@emotion/babel-preset-css-prop
version: 11.2.0@emotion/babel-plugin
version: 11.3.0I think this is probably the same issue as #2121 since Next.JS also sets
{modules: false}
for@babel/preset-env
and is presumably trying to run Emotion in Node for SSR.The text was updated successfully, but these errors were encountered: