Module not found: Can't resolve '@swc/helpers/src/_class_private_field_init.mjs' using NextUI with Next.js 13
Asked Answered
B

6

13

I´m trying to use NextUI with the latest version of Next.js 13. Following the official documentation of NextUI I have followed these steps:

  1. Install NextUI for Next.js

npm i @nextui-org/react

2.Go to pages/_app.js and add this:

// 1. import `NextUIProvider` component
import { NextUIProvider } from '@nextui-org/react';

function MyApp({ Component, pageProps }) {
  return (
    // 2. Use at the root of your app
    <NextUIProvider>
      <Component {...pageProps} />
    </NextUIProvider>
  );
}

export default MyApp;

3.Go to pages/_document.js and add this:

import React from 'react';
import Document, { Html, Head, Main, NextScript } from 'next/document';
import { CssBaseline } from '@nextui-org/react';

class MyDocument extends Document {
  static async getInitialProps(ctx) {
    const initialProps = await Document.getInitialProps(ctx);
    return {
      ...initialProps,
      styles: React.Children.toArray([initialProps.styles])
    };
  }

  render() {
    return (
      <Html lang="en">
        <Head>{CssBaseline.flush()}</Head>
        <body>
          <Main />
          <NextScript />
        </body>
      </Html>
    );
  }
}

export default MyDocument;

After that i run npm run dev command and the console show the following error:

error - ./node_modules/@internationalized/date/dist/import.mjs:1:0
Module not found: Can't resolve '@swc/helpers/src/_class_private_field_init.mjs'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/@react-aria/i18n/dist/real-module.js
./node_modules/@react-aria/i18n/dist/module.js
./node_modules/@nextui-org/react/esm/index.js
./pages/_app.js

Does anyone know what might be happening?

I´ve checked and "_class_private_field_init.mjs" is in the right path. And I have also tried reinstalling the node_modules

Boggess answered 23/4, 2023 at 6:31 Comment(0)
A
10

Upgrading to 13.4.7 worked for me

Acarid answered 29/6, 2023 at 23:22 Comment(2)
Confirmed, updated from [email protected] to [email protected], error resolved. Wasn't using NextUI, but instead HeadlessUI. Unsure what the common dependency/issue is though.Lille
I had a similar experience to what Xevion describes. I was also using HeadlessUI. I used the next.js upgrade guide nextjs.org/docs/pages/building-your-application/upgrading/…Pickar
M
3

If you will use nextjs version "13.3.0" the issue should be resolved. Important note is that you should use exact version. More info in this comment https://github.com/vercel/next.js/issues/48593#issuecomment-1519914997

Microcrystalline answered 24/4, 2023 at 13:31 Comment(0)
D
3

In your terminal copy and paste

npm install @swc/helpers

The issue should be solved.

Drupelet answered 19/6, 2023 at 14:7 Comment(2)
that doest helpWane
Why exactly do you think this would work? Because it doesn't.Lille
M
1

it working well with "next": "13.3.0" version. Try to downgrade the next version.

Metaplasm answered 24/4, 2023 at 10:57 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Prude
C
0

Try using the lower version while the bug is being fixed in future releases.

package.json

{
  ...
  "dependencies": {
        "next": "13.2.4",
    ...
    }
}
Candiot answered 23/4, 2023 at 12:57 Comment(1)
In my case this solution did not work, but thanks anyway.Chiquia
M
0

Try using the lower version while the bug is being fixed in future releases.

package.json:

{
  "dependencies": {
        "next": "13.2.4",
    }
}

then run npm install.


It works in my case.

Mulish answered 23/4, 2023 at 20:43 Comment(1)
This has worked for me as well in an NX project.Amalgamation

© 2022 - 2024 — McMap. All rights reserved.