vercel / next.js

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

Get "modularize-import-loader" errors when running next 13 with turbo flag #54686

Open dannygooze opened 1 year ago

dannygooze commented 1 year ago

Verify canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.14.2
      npm: 9.5.0
      Yarn: 1.22.19
      pnpm: N/A
    Relevant Packages:
      next: 13.4.20-canary.11
      eslint-config-next: 13.4.19
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.2.2
    Next.js Config:
      output: N/A

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

App Router, Dynamic imports (next/dynamic)

Link to the code that reproduces this issue or a replay of the bug

https:github.com/dannygooze/test-turbo-reo

To Reproduce

  1. yarn create next-app --experimental-app
  2. yarn add @headlessui/react
  3. Edit dev script in package.json to be "next dev --turbo"
  4. Add a headlessui component to page.tsx, see repo for example
  5. Run yarn dev
  6. See error in browser

Describe the Bug

When running a next 13 app with turbo, yarn packages are having a hard time resolving due to the way turbo tries to modularize imports. I have tried updating the next config to get this to work and find the correct modules with no luck.

Here is what I have tried adding in my next config:

modularizeImports: { "@headlessui/react": { transform: "@headlessui/react/dist/components/{{kebabCase member}}/{{kebabCase member}}" } }

Expected Behavior

Expect this to run and import the components from yarn packages.

Which browser are you using? (if relevant)

Chrome

How are you deploying your application? (if relevant)

Vercel

weyert commented 1 year ago

Looks like it's related to my issue: https://github.com/vercel/next.js/issues/54286

srs81 commented 1 year ago

Having this exact same error with Next 13 using turbo and @headlessui/react . It looks like this issue in turbo maybe related as well https://github.com/vercel/turbo/issues/4763

weyert commented 1 year ago

Ain't it already added in the latest version of the canary build? https://github.com/vercel/next.js/blob/canary/packages/next/src/server/config.ts#L674