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

[turbopack] [next/og] monorepo fails to resolve workspace node_modules in root node_modules #65614

Open
dylanirion opened this issue May 10, 2024 · 3 comments
Labels
bug Issue was opened via the bug report template. linear: turbopack Confirmed issue that is tracked by the Turbopack team. Module Resolution Module resolution (CJS / ESM, module resolving) Turbopack Related to Turbopack with Next.js.

Comments

@dylanirion
Copy link

dylanirion commented May 10, 2024

Link to the code that reproduces this issue

https://github.com/dylanirion/og-monorepo

To Reproduce

  1. Start the application in dev mode cd apps/app && pnpm run dev
  2. Navigate to http://localhost:3000/opengraph-image

Current vs. Expected behavior

Following the steps in the previous section, I expect to see an image with black text "About Acme" on a white background. This is the case when using webpack instead of turbopack.

A 500 error occurs instead, where it appears node is trying to resolve a filepath from the project root node_modules folder, inside the workspace node_modules folder

 ⨯ Error: failed to pipe response
    at pipeToNodeResponse (/home/dylan/og-monorepo/node_modules/.pnpm/next@14.3.0-canary.54_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/pipe-readable.js:126:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async sendResponse (/home/dylan/og-monorepo/node_modules/.pnpm/next@14.3.0-canary.54_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/send-response.js:42:13)
    at async doRender (/home/dylan/og-monorepo/node_modules/.pnpm/next@14.3.0-canary.54_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/base-server.js:1409:25)
    at async responseGenerator (/home/dylan/og-monorepo/node_modules/.pnpm/next@14.3.0-canary.54_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/base-server.js:1593:40)
    at async DevServer.renderToResponseWithComponentsImpl (/home/dylan/og-monorepo/node_modules/.pnpm/next@14.3.0-canary.54_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/base-server.js:1618:28)
    at async DevServer.renderPageComponent (/home/dylan/og-monorepo/node_modules/.pnpm/next@14.3.0-canary.54_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/base-server.js:1931:24)
    at async DevServer.renderToResponseImpl (/home/dylan/og-monorepo/node_modules/.pnpm/next@14.3.0-canary.54_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/base-server.js:1969:32)
    at async DevServer.pipeImpl (/home/dylan/og-monorepo/node_modules/.pnpm/next@14.3.0-canary.54_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/base-server.js:902:25)
    at async NextNodeServer.handleCatchallRenderRequest (/home/dylan/og-monorepo/node_modules/.pnpm/next@14.3.0-canary.54_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/next-server.js:273:17)
    at async DevServer.handleRequestImpl (/home/dylan/og-monorepo/node_modules/.pnpm/next@14.3.0-canary.54_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/base-server.js:798:17)
    at async /home/dylan/og-monorepo/node_modules/.pnpm/next@14.3.0-canary.54_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/dev/next-dev-server.js:339:20
    at async Span.traceAsyncFn (/home/dylan/og-monorepo/node_modules/.pnpm/next@14.3.0-canary.54_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/trace/trace.js:157:20)
    at async DevServer.handleRequest (/home/dylan/og-monorepo/node_modules/.pnpm/next@14.3.0-canary.54_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/dev/next-dev-server.js:336:24)
    at async invokeRender (/home/dylan/og-monorepo/node_modules/.pnpm/next@14.3.0-canary.54_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/lib/router-server.js:174:21)
    at async handleRequest (/home/dylan/og-monorepo/node_modules/.pnpm/next@14.3.0-canary.54_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/lib/router-server.js:353:24)
    at async requestHandlerImpl (/home/dylan/og-monorepo/node_modules/.pnpm/next@14.3.0-canary.54_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/lib/router-server.js:377:13)
    at async Server.requestListener (/home/dylan/og-monorepo/node_modules/.pnpm/next@14.3.0-canary.54_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/lib/start-server.js:142:13) {
  [cause]: Error: ENOENT: no such file or directory, open '/home/dylan/og-monorepo/apps/app/node_modules/.pnpm/next@14.3.0-canary.54_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/compiled/@vercel/og/noto-sans-v27-latin-regular.ttf'
      at Object.openSync (node:fs:581:18)
      at Object.readFileSync (node:fs:457:35)
      at /home/dylan/og-monorepo/apps/app/.next/server/chunks/a9760_next_dist_compiled_@vercel_og_index_node_855f1f.js:25675:65
      at [project]/node_modules/.pnpm/next@14.3.0-canary.54_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/compiled/@vercel/og/index.node.js [app-rsc] (ecmascript) (/home/dylan/og-monorepo/apps/app/.next/server/chunks/a9760_next_dist_compiled_@vercel_og_index_node_855f1f.js:25750:3)
      at instantiateModule (/home/dylan/og-monorepo/apps/app/.next/server/chunks/[turbopack]_runtime.js:520:23)
      at getOrInstantiateModuleFromParent (/home/dylan/og-monorepo/apps/app/.next/server/chunks/[turbopack]_runtime.js:572:12)
      at esmImport (/home/dylan/og-monorepo/apps/app/.next/server/chunks/[turbopack]_runtime.js:122:20)
      at /home/dylan/og-monorepo/apps/app/.next/server/chunks/a9760_next_dist_compiled_@vercel_og_index_node_2eac83.js:9:16
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async Object.start (/home/dylan/og-monorepo/apps/app/.next/server/chunks/a9760_next_bf1c7f._.js:7383:18) {
    errno: -2,
    code: 'ENOENT',
    syscall: 'open',
    path: '/home/dylan/og-monorepo/apps/app/node_modules/.pnpm/next@14.3.0-canary.54_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/compiled/@vercel/og/noto-sans-v27-latin-regular.ttf'
  }
}

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP Fri Mar 29 23:14:13 UTC 2024
  Available memory (MB): 13982
  Available CPU cores: 12
Binaries:
  Node: 20.11.1
  npm: 10.7.0
  Yarn: 1.22.19
  pnpm: 9.1.0
Relevant Packages:
  next: 14.3.0-canary.54 // Latest available version is detected (14.3.0-canary.54).
  eslint-config-next: 14.3.0-canary.54
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 4.8.4
Next.js Config:
  output: N/A

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

Module Resolution, Turbopack

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

next dev (local)

Additional context

The reprex is based on the monorepo with turbopack example and minimal changes to bring next up to date.
I encountered this error in 14.2.3 but have not traced it back to earlier commits.

@dylanirion dylanirion added the bug Issue was opened via the bug report template. label May 10, 2024
@github-actions github-actions bot added Module Resolution Module resolution (CJS / ESM, module resolving) Turbopack Related to Turbopack with Next.js. labels May 10, 2024
@timneutkens
Copy link
Member

Thanks for the great reproduction, makes it much easier to figure out where exactly the problem is 🙏

Did some digging and found that it's specifically require.resolve('@acme/ui') in tailwind.cjs, which is the Tailwind config that is imported in tailwind.config.js. Must be something related to the way that the postcss loader is executed.

@timneutkens timneutkens added the linear: turbopack Confirmed issue that is tracked by the Turbopack team. label May 11, 2024
@dylanirion
Copy link
Author

Thanks for having a look!

I've stripped back the reprex even further to remove Tailwind and PostCSS.
The error seems to originate on line 22 of image-response.ts but I think the actual issue is outside of next.js and somewhere between (p)npm/turbopack/tsconfig failing to find a hoisted node_modules

@dylanirion
Copy link
Author

Possibly related? #2783

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. linear: turbopack Confirmed issue that is tracked by the Turbopack team. Module Resolution Module resolution (CJS / ESM, module resolving) Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

No branches or pull requests

2 participants