vercel / next.js

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

`optimizePackageImports` + `rxjs` fails to build in a turborepo #55818

Open decepulis opened 9 months ago

decepulis commented 9 months ago

Link to the code that reproduces this issue

https://github.com/decepulis/nextjs-barrel-reproduction

To Reproduce

I created a new turborepo and installed next@canary in the example web and docs directories. I then installed rxjs in the web directory.

apps/web/app/page.tsx has the following import:

import { interval, take, lastValueFrom } from "rxjs";

Current vs. Expected behavior

yarn build results in the following errors:

Attempted import error: 'take' is not exported from '__barrel_optimize__?names=interval,lastValueFrom,take!=!rxjs' (imported as 'take').
Attempted import error: 'lastValueFrom' is not exported from '__barrel_optimize__?names=interval,lastValueFrom,take!=!rxjs' (imported as 'lastValueFrom').
Here's a full log of the build, filtered by web for clarity
dcepulis@dc-mux nextjs-barrel-reproduction % yarn build --filter=web
yarn run v1.22.17
$ turbo run build --filter=web
• Packages in scope: web
• Running build in 1 packages
• Remote caching disabled
web:build: cache miss, executing 5279913fc08b516e
web:build: $ next build
web:build:    Creating an optimized production build ...
web:build:  ⚠ Compiled with warnings
web:build: 
web:build: ./app/page.tsx
web:build: Attempted import error: 'take' is not exported from '__barrel_optimize__?names=interval,lastValueFrom,take!=!rxjs' (imported as 'take').
web:build: 
web:build: Import trace for requested module:
web:build: ./app/page.tsx
web:build: 
web:build: ./app/page.tsx
web:build: Attempted import error: 'lastValueFrom' is not exported from '__barrel_optimize__?names=interval,lastValueFrom,take!=!rxjs' (imported as 'lastValueFrom').
web:build: 
web:build: Import trace for requested module:
web:build: ./app/page.tsx
web:build: 
web:build:    Linting and checking validity of types ...
web:build:    Collecting page data ...
web:build:    Generating static pages (0/5) ...
   Generating static pages (1/5) 
   Generating static pages (2/5) 
   Generating static pages (3/5) 
web:build: TypeError: (0 , a.take) is not a function
web:build:     at p (/Users/dcepulis/Desktop/nextjs-barrel-reproduction/apps/web/.next/server/app/page.js:1:3477)
web:build:     at _ (/Users/dcepulis/Desktop/nextjs-barrel-reproduction/apps/web/.next/server/app/page.js:1:4276)
web:build:     at /Users/dcepulis/Desktop/nextjs-barrel-reproduction/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:1:429875
web:build:     at /Users/dcepulis/Desktop/nextjs-barrel-reproduction/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:1:430007
web:build:     at async ge (/Users/dcepulis/Desktop/nextjs-barrel-reproduction/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:1:429696)
web:build:     at async /Users/dcepulis/Desktop/nextjs-barrel-reproduction/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:1:428789
web:build:     at async Promise.all (index 0)
web:build:     at async ge (/Users/dcepulis/Desktop/nextjs-barrel-reproduction/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:1:428553)
web:build:     at async /Users/dcepulis/Desktop/nextjs-barrel-reproduction/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:1:434268
web:build: 
web:build: Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
web:build: TypeError: (0 , a.take) is not a function
web:build:     at p (/Users/dcepulis/Desktop/nextjs-barrel-reproduction/apps/web/.next/server/app/page.js:1:3477)
web:build:     at _ (/Users/dcepulis/Desktop/nextjs-barrel-reproduction/apps/web/.next/server/app/page.js:1:4276)
web:build:     at /Users/dcepulis/Desktop/nextjs-barrel-reproduction/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:1:429875
web:build:     at /Users/dcepulis/Desktop/nextjs-barrel-reproduction/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:1:430007
web:build:     at async ge (/Users/dcepulis/Desktop/nextjs-barrel-reproduction/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:1:429696)
web:build:     at async /Users/dcepulis/Desktop/nextjs-barrel-reproduction/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:1:428789
web:build:     at async Promise.all (index 0)
web:build:     at async ge (/Users/dcepulis/Desktop/nextjs-barrel-reproduction/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:1:428553)
web:build:     at async /Users/dcepulis/Desktop/nextjs-barrel-reproduction/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:1:434268
 ✓ Generating static pages (5/5) 
web:build: 
web:build: > Export encountered errors on following paths:
web:build:      /page: /
web:build: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
web:build: error Command failed with exit code 1.
web:build: ERROR: command finished with error: command (/Users/dcepulis/Desktop/nextjs-barrel-reproduction/apps/web) yarn run build exited (1)
web#build: command (/Users/dcepulis/Desktop/nextjs-barrel-reproduction/apps/web) yarn run build exited (1)

 Tasks:    0 successful, 1 total
Cached:    0 cached, 1 total
  Time:    5.242s 
Failed:    web#build

 ERROR  run failed: command  exited (1)
error Command failed with exit code 1.

Verify canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000
Binaries:
  Node: 18.16.0
  npm: 9.5.1
  Yarn: 1.22.17
  pnpm: 7.12.2
Relevant Packages:
  next: 13.5.3-canary.1
  eslint-config-next: 13.5.3-canary.1
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 4.9.5
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router, SWC transpilation

Additional context

NEXT-1684

lbittner-pdftron commented 9 months ago

+1 - I can reproduce this by importing @sanity/client. I'm seeing this error without Turbo, its happening in a webpack environment

zalolorza commented 8 months ago

+1. The issue persists on Next 14.0.0. At the moment, @sanity/client is not usable above 13.4

lbittner-pdftron commented 8 months ago

Hey @shuding, any updates on this issue? This issue is blocking us from upgrading to Next.js 13 or 14 and is not resolved in Next 14. We cannot downgrade to <13.4 as we need the permanentRedirect function that was introduced in a later version.

endosama commented 7 months ago

Experiencing the same issue also on next 13.4.19. Is there any way to disable the optimisation without having to downgrade?

eivindml commented 5 months ago

Any progress? I'm experiencing the same issue with @sanity/client and nextjs 14.

dennis-pushh commented 5 months ago

Same issue with @sanity/client. Any Updates?

CN-M commented 4 months ago

Same issue with @sanity/client and nextjs 14. Would definitely appreciate any updates.

eivindml commented 3 weeks ago

Looks like this is fixed in the latest release of Next. I tested if @sanity/client and next-sanity still gave the same error in my repo (they did), and then updated to next@latest. Now it works with latest sanity clients.