next.js: Build time error: Can't resolve @swc/helpers/...

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

> ./node_modules/.bin/next info

    Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.4.0: Mon Mar  6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.15.0
      npm: 9.6.4
      Yarn: N/A
      pnpm: 8.2.0
    Relevant packages:
      next: 13.3.1-canary.16
      eslint-config-next: 13.3.1-canary.16
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true)

Link to the code that reproduces this issue

https://github.com/jianliao/nextjs-rsp-bug

To Reproduce

  1. Git clone https://github.com/jianliao/nextjs-rsp-bug
  2. npm i
  3. npm run build

The issue is exactly same as #38192.

Describe the Bug

After upgrade to next@13.3.1-canary.16, next build will fail with below error messages:

> nextjs-rsp-table@0.1.0 build
> next build

warn  - You have enabled experimental feature (appDir) in next.config.js.
warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
info  - Thank you for testing `appDir` please leave your feedback at https://nextjs.link/app-feedback

Failed to compile.

./node_modules/@internationalized/date/dist/import.mjs
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-spectrum/calendar/dist/import.mjs
./node_modules/@adobe/react-spectrum/dist/import.mjs
./app/page.tsx

./node_modules/@internationalized/date/dist/import.mjs
Module not found: Can't resolve '@swc/helpers/src/_define_property.mjs'

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

Import trace for requested module:
./node_modules/@react-spectrum/calendar/dist/import.mjs
./node_modules/@adobe/react-spectrum/dist/import.mjs
./app/page.tsx

./node_modules/@react-aria/focus/dist/import.mjs
Module not found: Can't resolve '@swc/helpers/src/_define_property.mjs'

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

Import trace for requested module:
./node_modules/@react-spectrum/actiongroup/dist/import.mjs
./node_modules/@adobe/react-spectrum/dist/import.mjs
./app/page.tsx

./node_modules/@react-stately/collections/dist/import.mjs
Module not found: Can't resolve '@swc/helpers/src/_define_property.mjs'

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

Import trace for requested module:
./node_modules/@adobe/react-spectrum/dist/import.mjs
./app/page.tsx

./node_modules/@react-stately/grid/dist/import.mjs
Module not found: Can't resolve '@swc/helpers/src/_define_property.mjs'

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

Import trace for requested module:
./node_modules/@react-stately/table/dist/import.mjs
./node_modules/@react-spectrum/table/dist/import.mjs
./node_modules/@adobe/react-spectrum/dist/import.mjs
./app/page.tsx


> Build failed because of webpack errors
info  - Creating an optimized production build .%

Expected Behavior

Build success.

Which browser are you using? (if relevant)

Chrome 113.0.5672.35

How are you deploying your application? (if relevant)

next build

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 19
  • Comments: 62 (19 by maintainers)

Commits related to this issue

Most upvoted comments

Maybe this could be given extra attention? This literally bombs when trying to follow the Getting Started guide. Thanks!

Having this problem in v13.3.1. Using simple turborepo here.

yarn start 2023-04-22 at 2 18 16 PM

How to fix this bug in nextjs@12.x ?

npm overrides: https://docs.npmjs.com/cli/v9/configuring-npm/package-json#overrides

"overrides": {
  "next": {
    "@swc/helpers": "0.4.36"
  }
}

yarn resolutions: https://yarnpkg.com/configuration/manifest#resolutions

"resolutions": {
  "next/@swc/helpers": "0.4.36"
},

pnpm.overrides https://pnpm.io/package_json#pnpmoverrides

"pnpm": {
  "overrides": {
    "@swc/helpers@~0.4": "0.4.36"
  }
}

I had such error for react-aria on "next": "13.3.1". Downgrading to "next": "13.3.0" helped.

P.S. probably you need to set exact version, if you already have 13.3.1 in lock file changing version from "next": "^13.3.1" to "^13.3.0". will probably make no effect since the versions are compatible because of ^

I’m also wondering if somebody knows how to fix this with Next 12.x, using patch-package or whatever.

I was about to ask the same thing

I’m also wondering if somebody knows how to fix this with Next 12.x, using patch-package or whatever.

I had such error for react-aria on "next": "13.3.1". Downgrading to "next": "13.3.0" helped.

P.S. probably you need to set exact version, if you already have 13.3.1 in lock file changing version from "next": "^13.3.1" to "^13.3.0". will probably make no effect since the versions are compatible because of ^

yeah, I also noticed that some early version work if you don’t use the ^

For people looking for a temporary fix you can use this workaround

https://github.com/vercel/next.js/issues/48577

this issue is not only attached to @swc/helpers this issue es related to all packages that has different versions installed in monorepo. This is failing only in this because the helpers change from the v0.4 to the 0.5 the structure so when resolving to the last version that src folder does not exist

also if you use turbopack the issue does not exist.

Getting the same with @internationalized/date - seems related to Adobe packages.

It’s now fixed 😄

You must update @swc/helpers of next package. If you are using yarn, you can do like


  "resolutions": {
    "next/@swc/helpers": "0.4.36"
  }

https://github.com/kdy1/bug-next-12-swc-helpers/blob/140abb8b18ccfac263356cc686c061bbfba795f5/package.json#L16-L18

Thank you @devongovett and @magic-akari

Maybe someone from the @vercel team can patch next@12 to fix it issue

I still have this issue with Jest when using Next 13.4.4. The latest Next version that works for me is 13.3.0.

I have the issue on 13.3.0 oddly.

Confirmed. The issue had been fixed on next@13.3.2-canary.6 for my reproducer repo.

https://github.com/vercel/next.js/blob/2f6ff0dab330b854c43a1773be2fe739c3582419/packages/next/src/build/webpack-config.ts#L1070-L1072

This is the cause. There’s no logic for respecting the semver of @swc/helpers.

@magic-akari How do you think about exposing @swc/helpers/src/xxx.mjs along with the new helpers (@swc/helpers/_/*) to workaround this issue (for a while)?

Technically, this is not a problem of SWC, but I’m not sure if specifying semver in resolve.alias of webpack is possible.

I have posted a solution in the meantime this get resolved, look here for the webpack simple plugin

here just in case:

https://github.com/vercel/next.js/issues/48593#issuecomment-1519111776

When using 13.2.x everything works fine. This is 4 days open and literally makes the framework unusable, will anyone fix this?

I’m getting the same errors using Turborepo. My additional information mimic for the original reports but I also hopped over to a machine to confirm the results and those details are below. So I’ve received the same result on both MacOS and Windows. I, too am starting from ‘getting started’ so this Next app is brand new, but been a non-starter as this presents itself right out the gate.

Thanks and let me know if I can provide any better detail. I can post my macOS details as needed but they mimic the og post as mentioned earlier.

> prodkt-builder@0.1.0 build C:\ProdktDevelopment\prodkt-cloud\apps\prodkt-builder
> next build

info  - Skipping linting
info  - Checking validity of types...
info  - Creating an optimized production build...
Failed to compile.

../../node_modules/@internationalized/date/dist/import.mjs
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.mjs
../../node_modules/@react-aria/i18n/dist/import.mjs
../../node_modules/@react-aria/select/dist/import.mjs
../../node_modules/@plasmicapp/react-web/dist/react-web.esm.js
./pages/_app.tsx

../../node_modules/@internationalized/date/dist/import.mjs
Module not found: Can't resolve '@swc/helpers/src/_define_property.mjs'

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

Import trace for requested module:
../../node_modules/@react-aria/i18n/dist/real-module.mjs
../../node_modules/@react-aria/i18n/dist/import.mjs
../../node_modules/@react-aria/select/dist/import.mjs
../../node_modules/@plasmicapp/react-web/dist/react-web.esm.js
./pages/_app.tsx

../../node_modules/@react-aria/focus/dist/import.mjs
Module not found: Can't resolve '@swc/helpers/src/_define_property.mjs'

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

Import trace for requested module:
../../node_modules/@plasmicapp/react-web/dist/react-web.esm.js
./pages/_app.tsx

../../node_modules/@react-stately/collections/dist/import.mjs
Module not found: Can't resolve '@swc/helpers/src/_define_property.mjs'

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

Import trace for requested module:
../../node_modules/@plasmicapp/react-web/dist/react-web.esm.js
./pages/_app.tsx

../../node_modules/@react-stately/list/dist/import.mjs
Module not found: Can't resolve '@swc/helpers/src/_define_property.mjs'

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

Import trace for requested module:
../../node_modules/@react-stately/select/dist/import.mjs
../../node_modules/@plasmicapp/react-web/dist/react-web.esm.js
./pages/_app.tsx


> Build failed because of webpack errors
 ELIFECYCLE  Command failed with exit code 1.

    Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Home
    Binaries:
      Node: 16.20.0
      npm: N/A
      Yarn: N/A
      pnpm: 8.1.1
    Relevant packages:
      next: 13.3.1
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0

I still have this issue with Jest when using Next 13.4.4. The latest Next version that works for me is 13.3.0.

v13.3.2 officially released to solve this issue. See: https://github.com/vercel/next.js/releases/tag/v13.3.2

I still have this issue with Jest and @swc/jest also errors coming from the react-aria packages

for some reason im getting this error in next v13.2.4 . It was working until I installed @react-aria/i18n, I can’t figure out why

@huykon It’s released in v13.3.2-canary.6

do we have any release versions to fix this issue?

I had such error for react-aria on "next": "13.3.1". Downgrading to "next": "13.3.0" helped.

P.S. probably you need to set exact version, if you already have 13.3.1 in lock file changing version from "next": "^13.3.1" to "^13.3.0". will probably make no effect since the versions are compatible because of ^

Thanks! Resolved ✅

I had such error for react-aria on "next": "13.3.1". Downgrading to "next": "13.3.0" helped.

P.S. probably you need to set exact version, if you already have 13.3.1 in lock file changing version from "next": "^13.3.1" to "^13.3.0". will probably make no effect since the versions are compatible because of ^

Good tip actually, I was under the assumption I had to go back to 12.2.x because I use ~ which uses latest patch version. So ~13.3.0 = 13.3.1

I am pretty sure this issue was introduced by version v13.3.1-canary.12.