question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with type `module` exports in Next js

See original GitHub issue

First 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",
        ]
      : [],
  };
};

image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
navin-moorthycommented, Oct 18, 2021

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.

1reaction
navin-moorthycommented, Oct 19, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found