Skip to content
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

NextJS, esm/cjs Server error. #8

Open
Idzikowski-Casey opened this issue Feb 2, 2022 · 0 comments
Open

NextJS, esm/cjs Server error. #8

Idzikowski-Casey opened this issue Feb 2, 2022 · 0 comments
Assignees

Comments

@Idzikowski-Casey
Copy link
Collaborator

When using ui-components with NextJs, I'm getting the following error:

nexterror

It appears that Next is loading the common js bundle, when we expect it to load the ESM bundle. This problem seems related to this issue. The best solution I have found is installing next-transpile-modules and enabling the experimental esmExternal option in the next.config.js.

The next.config.js file looks like this:

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  experimental: { esmExternals: true },
};

const withTM = require("next-transpile-modules")([
  "@macrostrat/hyper",
  "@macrostrat/ui-components",
]); // pass the modules you would like to see transpiled

module.exports = withTM(nextConfig);

After this, we can import ui-components directly through lib/esm. For instance:

import {
  ModelEditor,
  useModelEditor,
  ModelEditButton,
} from "@macrostrat/ui-components/lib/esm";

TL;DR:
Install next-transpile-modules and import @macrostrat/ui-components/lib/esm to fix esm error with nextjs.

@Idzikowski-Casey Idzikowski-Casey self-assigned this Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant