Issue with type `module` exports in Next js
See original GitHub issueFirst of all, there seems to be no issue when using tailwind-merge
directly inside a Next.js project.
Example: https://stackblitz.com/edit/nextjs-wxchtk?file=pages%2Findex.js
Issue for me is when I bundle tailwind-merge
along with my UI library & try to start Next.js.
Example: https://stackblitz.com/edit/next-tailwind-jit-evzkdg?file=components%2Findex.js
(error can be seen here)
My babel.config.js
to bundle my components with tailwind-merge
const BABEL_ENV = process.env.BABEL_ENV;
const isCommonJS = BABEL_ENV !== undefined && BABEL_ENV === "cjs";
const isESM = BABEL_ENV !== undefined && BABEL_ENV === "esm";
const isBuild = !!BABEL_ENV;
module.exports = function (api) {
api.cache(true);
const presets = [
[
"@babel/env",
{
modules: isCommonJS ? "commonjs" : false,
targets: { esmodules: isESM ? true : undefined },
},
],
["@babel/preset-react", { runtime: "automatic" }],
"@babel/preset-typescript",
];
const plugins = [
["@babel/plugin-proposal-class-properties", { loose: true }],
["@babel/plugin-proposal-logical-assignment-operators", { loose: true }],
["@babel/plugin-proposal-private-property-in-object", { loose: true }],
["@babel/plugin-proposal-private-methods", { loose: true }],
["lodash"],
isBuild
? [
"babel-plugin-jsx-remove-data-test-id",
{ attributes: ["data-testid"] },
]
: {},
];
return {
presets,
plugins,
env: {
test: {
presets: [["@babel/env", { targets: { node: "current" } }]],
},
},
ignore: isBuild
? [
"**/*/stories",
"**/__tests__",
"**/testUtils.tsx",
"./renderlesskit.config.ts",
]
: [],
};
};
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to Bypass ES Modules Errors in Next.js with Dynamic ...
They have modules that are exporting a particular function (it could be a JavaScript component), an object, a string, a bunch of arrays,...
Read more >module-not-found - Next.js
The module you're trying to import has a different casing. Make sure the casing of the file is correct. Example: // components/MyComponent.js export...
Read more >next.config.js: Introduction
next.config.js is a regular Node.js module, not a JSON file. ... NextConfig} */ const nextConfig = { /* config options here */ }...
Read more >Advanced Features: Static HTML Export | Next.js
next export allows you to export your Next.js application to static HTML, which can be run standalone without the need of a Node.js...
Read more >Advanced Features: Dynamic Import - Next.js
Dynamically import JavaScript modules and React Components and split your code ... To dynamically import a named export, you can return it from...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks @dcastil for your research on this issue, I also looked into this issue: vercel/next.js#25454 beforehand.
I will try adding the
exports
field & create an esm build using.mjs
extension.It Works 🎉
I also released a new version of my package & tried - https://stackblitz.com/edit/next-tailwind-jit-evzkdg?file=components%2Findex.js
Thank you very much.