vercel / next.js

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

next 14 can not resolve dependencies for installed server side packages correctly using plain js (works with typescript) #57659

Open erikarenhill opened 9 months ago

erikarenhill commented 9 months ago

Link to the code that reproduces this issue

https://github.com/erikarenhill/next-14-dependency-bug

To Reproduce

  1. create a new next project, select no when asked if you want to use typescript
  2. install ravendb client (5.4.1) (npm i ravendb)
  3. import { DocumentStore } from 'ravendb' in a server component or page
  4. run the project, npm run dev

Current vs. Expected behavior

Expected behaviour: The page loads correctly when using next 14 (as it does with 13.5)

Current behaviour: crash with Error: XRegExp is not a function

Verify canary release

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP Fri Jan 27 02:56:13 UTC 2023
Binaries:
  Node: 18.18.2
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 14.0.0
  eslint-config-next: 14.0.0
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

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

App Router, Package manager (npm, pnpm, Yarn)

Additional context

I have reproduced it locally using both node 18 and 20.

As it works with next 13.5 I'm adding this bug to the next project, as it looks like it can not resolve dependencies for libraries used correctly in the same way as 13.5.

I have tried with and without turbo and it does not matter

erikarenhill commented 9 months ago

adding ravendb to serverComponentsExternalPackages resolves this issue.

erikarenhill commented 9 months ago

it should however be consistent behaviour between typescript and not?

lucgagan commented 9 months ago

Thank you for the hint about serverComponentsExternalPackages. This saved the day.