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

Build time error: Can't resolve @swc/helpers/... #48593

Closed
1 task done
jianliao opened this issue Apr 19, 2023 · 62 comments · Fixed by #48808 or #48980
Closed
1 task done

Build time error: Can't resolve @swc/helpers/... #48593

jianliao opened this issue Apr 19, 2023 · 62 comments · Fixed by #48808 or #48980
Assignees
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. locked

Comments

@jianliao
Copy link

jianliao commented Apr 19, 2023

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

@jianliao jianliao added the bug Issue was opened via the bug report template. label Apr 19, 2023
@github-actions github-actions bot added the area: app App directory (appDir: true) label Apr 19, 2023
@jianliao
Copy link
Author

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

@joacub
Copy link

joacub commented Apr 20, 2023

You are using probably a monorepo if is the case I have posted one workaround in the meantime

@jianliao
Copy link
Author

Thank you for your reply. Yes, our project uses a monorepo package called @adobe/react-spectrum, which is an umbrella package that is used in all the React Spectrum component packages. This is a fairly common pattern for a UI component library. However, it is important to note that Next.js supported this usage until v13.3.1-canary.12. Therefore, we hope that Next.js will continue to support this usage in future versions as well.

@jianliao
Copy link
Author

jianliao commented Apr 20, 2023

I found a potential related swc-project/swc#5009 in swc-project/swc repo.

@jianliao
Copy link
Author

Tried v13.3.1-canary.17, problem still exists.

@dvakatsiienko
Copy link
Contributor

dvakatsiienko commented Apr 22, 2023

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

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

@aperepel
Copy link

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

@prodkt
Copy link

prodkt commented Apr 23, 2023

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

@castrosu
Copy link

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

@b-bot
Copy link
Contributor

b-bot commented Apr 23, 2023

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

@joacub
Copy link

joacub commented Apr 23, 2023

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

#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.

@jianliao
Copy link
Author

jianliao commented Apr 23, 2023

@joacub, thanks for sharing your findings and the temporary workaround in #48577. I appreciate your insight on the issue and the connection with monorepos.

  1. I also confirmed that all the @adobe/react-* packages depend on @swc/helpers@^0.4.14 and that Next.js upgraded to @swc/helpers@0.5.0 in its canary v13.3.1-canary.12 release.
  2. I find it surprising that this is not considered a breaking change from the point of view of the @swc/helpers library. As you mentioned, the package folder structure has completely changed, and all the package entry points are different. This could potentially cause compatibility issues for dependent packages.
  3. Regarding the bug reproducer repo I posted in this Github issue, I found that even when installing the npm package using --install-strategy=nested, the build still fails with the same reason.

It's worth noting that if the issue doesn't exist when using turbopack, it could be an alternative solution for some users. However, it would be helpful if the @swc/helpers maintainers could clarify whether the changes between v0.4 and v0.5 should be considered breaking and if there is a recommended migration path for dependent packages.

@jianliao
Copy link
Author

image

@joacub
Copy link

joacub commented Apr 23, 2023

@joacub, thanks for sharing your findings and the temporary workaround in #48577. I appreciate your insight on the issue and the connection with monorepos.

  1. I also confirmed that all the @adobe/react-* packages depend on @swc/helpers@^0.4.14 and that Next.js upgraded to @swc/helpers@0.5.0 in its canary v13.3.1-canary.12 release.
  2. I find it surprising that this is not considered a breaking change from the point of view of the @swc/helpers library. As you mentioned, the package folder structure has completely changed, and all the package entry points are different. This could potentially cause compatibility issues for dependent packages.
  3. Regarding the bug reproducer repo I posted in this Github issue, I found that even when installing the npm package using --install-strategy=nested, the build still fails with the same reason.

It's worth noting that if the issue doesn't exist when using turbopack, it could be an alternative solution for some users. However, it would be helpful if the @swc/helpers maintainers could clarify whether the changes between v0.4 and v0.5 should be considered breaking and if there is a recommended migration path for dependent packages.

In monorepos is valid to have different versions not compatible each other, Webpack or nextjs is just not resolving correctly to the package.json node_modules relative to that package, the package exist and it is installed, webpack is just not doing right or next i don’t know who , that’s why the plug-in in Webpack resolved correctly which is a pretty easy solution and I’m really suprised that Webpack is not resolving correctly as that’s how webpack resolved usually. but I don’t know ….

@kdy1
Copy link
Member

kdy1 commented Apr 24, 2023

I think @swc/helpers@v0.4.x and @swc/helpers@v0.5.x is merged without checking semver compatibility.

@kdy1
Copy link
Member

kdy1 commented Apr 24, 2023

@jianliao A change from v0.4.x to v0.5.x is a breaking change.

@ap211unitech
Copy link

@castrosu
Copy link

castrosu commented Apr 24, 2023

This error is geting fixed by using nextjs version 13.2.4

https://stackoverflow.com/questions/76083438/module-not-found-cant-resolve-swc-helpers-src-class-private-field-init-mjs/76087179#76087179

Just like I said, if you use 13.2.x it works. Just not a great of a "fix" ah ah just use a version from couple months ago

@aspirisen
Copy link

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 ^

@castrosu
Copy link

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 ^

@b-bot
Copy link
Contributor

b-bot commented Apr 24, 2023

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

@2hmad
Copy link

2hmad commented Apr 24, 2023

I tried almost all solutions but the same issue! did anyone resolve it?

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
./src/providers/index.tsx
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: ENOENT: no such file or directory, rename 'xx/.next/cache/webpack/client-development-fallback/0.pack_' -> 'xx/.next/cache/webpack/client-development-fallback/0.pack'

@2hmad
Copy link

2hmad commented Apr 24, 2023

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 ✅

@dashkevych
Copy link

I am also experiencing similar issue with node_modules/next/node_modules/@swc/helpers in Next.js 13.3.1:

error - node_modules/next/node_modules/@swc/helpers/lib/_interop_require_wildcard.js (5:0) @ eval
error - TypeError: Cannot redefine property: default
    at Function.defineProperty (<anonymous>)

Installing Next.js 13.3.0 makes the issue disappear.

@kdy1
Copy link
Member

kdy1 commented Apr 25, 2023

'@swc/helpers': path.dirname(
require.resolve('@swc/helpers/package.json')
),

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.

@kdy1 kdy1 reopened this Apr 29, 2023
@kodiakhq kodiakhq bot closed this as completed in #48980 Apr 29, 2023
kodiakhq bot pushed a commit that referenced this issue Apr 29, 2023
### What?

Update resolve rule for `@swc/helpers` => `node_modules/@swc/helpers` to `@swc/helpers/_` => `node_modules/@swc/helpers/_` to select only `@swc/helpers@v0.5.0`.

### Why?

Previous rule make webpack merge `@swc/helpers@v0.4.x` and `@swc/helpers@v0.5.x`

### How?

Closes WEB-948
Fixes #48593
@salamaashoush
Copy link

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

@dvakatsiienko
Copy link
Contributor

@salamaashoush You may have try the recently released Next.js of version 13.3.2.
All the errors mentioned above was resolved in this version.
I have no errors with this new version of Next.js.

@camcam2605
Copy link

camcam2605 commented Apr 30, 2023

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

@salamaashoush
Copy link

yeah maybe I should report it on the react-aria or swc repo since I am not using nextjs and I have the same error but with jest, any help @kdy1?

@pierratono
Copy link

Facing this issue on next@13.3.4 after import { NextUIProvider } from '@nextui-org/react' into layout.tsx using appdir

@lucassimines
Copy link

When trying to deploy Docker on Ubuntu 22.04 I get the following:

Next version: 13.4.1

#20 36.34 Module not found: Can't resolve './projects/Card'
#20 36.34 
#20 36.34 https://nextjs.org/docs/messages/module-not-found
#20 36.34 
#20 36.34 ./src/app/projects/project/[slug]/Intro.tsx
#20 36.34 Module not found: Can't resolve '@/projects/Tags'
#20 36.34 
#20 36.34 https://nextjs.org/docs/messages/module-not-found
#20 36.34 
#20 36.34 ./src/app/about/page.tsx
#20 36.34 Module not found: Can't resolve './Intro'
#20 36.34 
#20 36.34 https://nextjs.org/docs/messages/module-not-found
#20 36.34 
#20 36.34 ./src/app/about/page.tsx
#20 36.34 Module not found: Can't resolve './Technologies'

But on my Macbook M1 using Docker the errors don't happen

@patik
Copy link

patik commented May 30, 2023

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.

@TechQuery
Copy link

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

@fraincs
Copy link

fraincs commented Jul 3, 2023

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.

@icopp
Copy link

icopp commented Jul 11, 2023

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

@ericanoronha
Copy link

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

@xkomiks
Copy link

xkomiks commented Jul 21, 2023

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

@yanyang729
Copy link

yanyang729 commented Jul 27, 2023

for next@12, a quick temporary fix is to pin the version in package.json

  "resolutions": {
    "@internationalized/date": "~3.0.1"
  }

@wuahi
Copy link

wuahi commented Jul 27, 2023

When trying to deploy Docker on Ubuntu 22.04 I get the following:

Next version: 13.4.1

#20 36.34 Module not found: Can't resolve './projects/Card'
#20 36.34 
#20 36.34 https://nextjs.org/docs/messages/module-not-found
#20 36.34 
#20 36.34 ./src/app/projects/project/[slug]/Intro.tsx
#20 36.34 Module not found: Can't resolve '@/projects/Tags'
#20 36.34 
#20 36.34 https://nextjs.org/docs/messages/module-not-found
#20 36.34 
#20 36.34 ./src/app/about/page.tsx
#20 36.34 Module not found: Can't resolve './Intro'
#20 36.34 
#20 36.34 https://nextjs.org/docs/messages/module-not-found
#20 36.34 
#20 36.34 ./src/app/about/page.tsx
#20 36.34 Module not found: Can't resolve './Technologies'

But on my Macbook M1 using Docker the errors don't happen

Same here, except for tsconfig paths. Help would be appreaciated:

Running build insinde alpine-18 container will yield:

Failed to compile.

./src/app/[locale]/logout/page.tsx
Module not found: Can't resolve '@/modules/common/hooks/useAuth'

@kdy1
Copy link
Member

kdy1 commented Aug 14, 2023

Is there a repro, if it still occurs?

@magic-akari
Copy link
Contributor

magic-akari commented Aug 14, 2023

There is a number of off-topic questions in this issue thread.
This issue topic is about @swc/helpers, while the other issues simply contain the keyword Can't resolve xxx. These are not the same issue.

If anyone has the problem with Can't resolve xxx, it's better to create a new issue thread.

@devongovett
Copy link

@kdy1 here's a repro: https://github.com/devongovett/next-swc-helpers-repro. It specifically occurs in Next 12 I think because Next's webpack config overrides the resolution to point to @swc/helpers@0.4? I'm not sure a new @swc/helpers@0.5 would help, because Next 12 has it pinned to 0.4.

@kdy1
Copy link
Member

kdy1 commented Aug 17, 2023

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

@magic-akari
Copy link
Contributor

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"
  }
}

@devongovett
Copy link

Thanks so much @kdy1 @magic-akari!

@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2023

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot added the locked label Sep 1, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. locked
Projects
None yet