payloadcms / payloadcms/payload

Unable to use Payload from the monorepo package.

Open
#11,774 7 comments 3 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

prioritized
Dominant language
TypeScript
Stars
44.8k
Forks
4.2k
Avg merge
2d 21h
Merged PRs (30d)
53

Description

Describe the Bug

Project structure: monorepo with yarn@1.22.x

I created a dedicated internal package to communicate with the CMS called ⁠@test/api. I want to use it in my internal monorepo app called ⁠@test/app. After I import ⁠import { fetchStuff } from @test/api in my Next.js app, there is an error as shown below.

Everything works if I connect to Payload directly inside my app.

Module not found: Can't resolve 'child_process'
  4 | 'use strict';
  5 |
> 6 | const childProcess = require('child_process');
    | ^
  7 | const { isLinux, getReport } = require('./process');
  8 | const { LDD_PATH, readFile, readFileSync } = require('./filesystem');
  9 |

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
../../node_modules/sharp/lib/utility.js
../../node_modules/sharp/lib/index.js
../cms/src/payload.config.ts
../api/src/index.ts
./pages/index.js
 ⨯ ../../node_modules/detect-libc/lib/detect-libc.js:6:1

In the Next.js error dialog, you will probably see a different error like

Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type; currently, no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

But my actual application shows the same error.

Link to the code that reproduces this issue

https://github.com/RafalFilipek/payload-monorepo-detect-libc-bug

Reproduction Steps
  1. Download repo
  2. Install dependencies with yarn@1.22
  3. Run application located in packages/app (yarn dev)
  4. Open http://localhost:3000
Which area(s) are affected? (Select all that apply)

Not sure

Environment Info
Payload: latest
NodeJS:  20.11.0 / 22.x
NextJS:  15.2.3
macOS:   15.3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.