I have my project set up in a monorepo like this (where "vipps" is a plugin):
(root)
package.json
/packages
/frontend-app1
/frontend-app2
/payload
package.json
/dist
/src
/payload-cms
/vipps
server.js
...
/src
/payload-cms
/vipps
server.ts
payload.config.ts
...I'm using Yarn Workspaces for all of these packages.
Webpack throws the following error on running payload (from
/dist) after build:
ERROR in main
Module not found: Error: Can't resolve 'C:\_repos\multitenant-1\payload\dist\admin' in 'C:\_repos\multitenant-1'Console logging Webpacks config.entry is the source of the error:
Webpack Entry: {main: Array(2)}
arg1: {main: Array(2)}
main: (2) ['C:\\_repos\\multitenant-1\\node_modules\\webpack-hot-middleware\\client.js?path=/admin/__webpack_hmr', 'C:\\_repos\\multitenant-1\\payload\\dist\\admin']
0: 'C:\\_repos\\multitenant-1\\node_modules\\webpack-hot-middleware\\client.js?path=/admin/__webpack_hmr'
1: 'C:\\_repos\\multitenant-1\\payload\\dist\\admin'
length: 2The path at
main[1]is incorrect (as you can see from my project structure), I think what it's looking for could be
C:\\_repos\\multitenant-1\\packages\\payload\\node_modules\\payload\\dist\\admin?
Here's the relevant part of my payload.config.ts (no customization):
export default buildConfig({
admin: {
bundler: webpackBundler(),
webpack: config => {
console.log('Webpack Entry:', config.entry)
console.log('Webpack Resolve:', config.resolve)
return { ...config }
}
},
...❓ Is a monorepo setup within the support scope of Payloads webpack bundling? If so, what's wrong with my config or what's missing?
❓ What's the best way to override or have the config be dynamically set?
TYSM.
Edit: Edited a path.
❗When I run dev (
ts-node src/payload-cms/server.ts) there's no issue.
hey
@735059082293149777did you find a solution? I have the same problem.
Hey. I encountered this when running a debugger in VS Code on built code. I abandoned it (still haven't got up the debugger), so nope nothing yet. But I've been able to build and serve the project since so I'll be looking into it again in a minute, will let you know if I find anything.
Alright, thanks for your swift reply! Someone in my dev team decided to intermediately compile our monorepo packages which are used by Payload.
Our structure is something like this:
apps/some-website (nextjs)
apps/payload-cms
packages/lib (some utilities, typescript)
packages/some-other-stuff
All of our /packages are in typescript, and did not contain any kind of distribution build or likewise. They were just directly imported into our apps through module
imports, and we never had the need for pre-built packages. But since payload is first only transpiled into JS, this broke our work flow.
As an intermediate solution we now use
tsupto quickly build our packages/lib, so it can be used by our apps/payload-cms dist build.
Finally we added
"@monorepo/lib": "file:../../packages/lib",to apps/payload-cms/package.json so it is treated as a regular node module.
Not the most elegant solution but for right now this works for us.
TYSM for the pointers, the transpilation thing could very well be related to the issues I was seeing.
The project was able to build and start later though so weird that the debugger specifically broke it.
I was able to get up a debugger for the dev files of my Payload app in my monorepo using this
launch.jsonconfiguration (credit to the Payload team - sorry I can't remember who forwarded this):
{
"command": "yarn run dev",
"name": "Dev Payload",
"request": "launch",
"type": "node-terminal",
"cwd": "${workspaceFolder}/packages/payload/src/"
}VS Code launch.json config in a monorepo (Incorrect Webpack config.entry in monorepo setup)
Star
Discord
online
Get dedicated engineering support directly from the Payload team.