vercel / next.js

The React Framework
https://nextjs.org
MIT License
127.04k stars 27k forks source link

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

Closed jianliao closed 1 year ago

jianliao commented 1 year ago

Verify 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

icopp commented 1 year ago

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

ericanoronha commented 1 year ago

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 commented 1 year ago

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

yanyang729 commented 1 year ago

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

  "resolutions": {
    "@internationalized/date": "~3.0.1"
  }
wuahi commented 1 year ago

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 commented 1 year ago

Is there a repro, if it still occurs?

magic-akari commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Thanks so much @kdy1 @magic-akari!

github-actions[bot] commented 1 year ago

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.