Open hdodov opened 7 months ago
I don't understand why Payload has to have common plugin files for front-end and back-end (single payload.config.ts
), resulting in messes like this. If both parts are separated and imported separately, a lot of this confusion could be avoided, in my opinion.
Sure, it might be annoying to have payload-server.config.ts
and payload-client.config.ts
, but I would much rather choose to manage two config files, than cross fingers every time I upgrade packages and have to debug and report issues. I ran into #4215 a while ago too.
Hey @hdodov , I understand your frustration. 3.0 will address all of the webpack woes directly.
I attempted to recreate this but was unable to run into any issues.
What package manager are you using? I attempted this with npm, yarn, and pnpm.
My steps:
npx create-payload-app@latest -t website --db mongodb recreate-4952
yarn add @payloadcms/plugin-cloud-storage@latest
yarn add @aws-sdk/client-s3 @aws-sdk/lib-storage aws-crt
cloudStorage({
collections: {
media: {
adapter: s3Adapter({
config: {
endpoint: process.env.S3_ENDPOINT,
forcePathStyle: process.env.S3_FORCE_PATH_STYLE === 'true',
region: process.env.S3_REGION,
credentials: {
accessKeyId: process.env.S3_ACCESS_KEY_ID,
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
},
},
bucket: process.env.S3_BUCKET,
}),
},
},
}),
yarn dev
Anything that I'm missing? A few other people have upvoted this issue, so I assume I'm missing something.
Can confirm I'm also running into this issue. I switched my adapter from postgres to mongo then all hell broke loose.
I am experiencing the same issue. Any solution yet?
@denolfe I've made a reproduction repo. Let me know if you can reproduce the issue now on your side. Look at the repo's README for instructions.
I decided to upgrade our dependencies today and the issue still persists:
<i> [webpack-dev-middleware] wait until bundle finished: /__webpack_hmr
<i> [webpack-dev-middleware] wait until bundle finished: /__webpack_hmr
<i> [webpack-dev-middleware] wait until bundle finished: /__webpack_hmr
webpack built 28c201726d1e6c071118 in 17355ms
ERROR in ./node_modules/fill-range/index.js 10:13-28
Module not found: Error: Can't resolve 'util' in '/app/node_modules/fill-range'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "util": require.resolve("util/") }'
- install 'util'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "util": false }
ERROR in ./node_modules/homedir-polyfill/index.js 3:9-22
Module not found: Error: Can't resolve 'os' in '/app/node_modules/homedir-polyfill'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "os": require.resolve("os-browserify/browser") }'
- install 'os-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "os": false }
ERROR in ./node_modules/micromatch/index.js 3:13-28
Module not found: Error: Can't resolve 'util' in '/app/node_modules/micromatch'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "util": require.resolve("util/") }'
- install 'util'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "util": false }
webpack compiled with 3 errors
Here are the versions of all Payload packages:
"@payloadcms/bundler-webpack": "^1.0.6",
"@payloadcms/db-mongodb": "^1.4.3",
"@payloadcms/plugin-cloud-storage": "^1.0.19",
"@payloadcms/richtext-slate": "^1.4.0",
"payload": "^2.11.2",
I had to downgrade @payloadcms/plugin-cloud-storage
from 1.1.2
to 1.0.19
again, as a workaround.
@hdodov Thank you for the reproduction. I was able to recreate.
However, it is quite confusing to me why setting the fallback of util: false
(as you did in your example) wouldn't handle this particular error.
I will have to tinker with this more to come to a solution.
@denolfe I decided to try to update the plugins again and set util: false
and os: false
due to the following errors:
ERROR in ./node_modules/fill-range/index.js 10:13-28
Module not found: Error: Can't resolve 'util' in '/app/node_modules/fill-range'
ERROR in ./node_modules/homedir-polyfill/index.js 3:9-22
Module not found: Error: Can't resolve 'os' in '/app/node_modules/homedir-polyfill'
ERROR in ./node_modules/micromatch/index.js 3:13-28
Module not found: Error: Can't resolve 'util' in '/app/node_modules/micromatch'
However, if I do this, I start getting the "process.getuid is not a function" error from the beginning of the issue, i.e. this:
There's no workaround at the moment, basically, and you're stuck to version 1.0.19 of the cloud storage plugin. You either get errors at compile time (because the module is being added and it shouldn't) or you get them in the frontend (because the module is not being added and it should).
I think the "solution" here is to wait for a stable Payload 3.0, but I'm just putting this out there for others who decide to give this a shot.
This package.json
"@payloadcms/bundler-webpack": "^1.0.6",
"@payloadcms/db-mongodb": "^1.4.3",
"@payloadcms/plugin-cloud-storage": "^1.0.19",
"@payloadcms/richtext-slate": "^1.4.0",
"payload": "^2.11.2",
With this payload.config.ts
webpack: (config) => {
return {
...config,
resolve: {
...config.resolve,
alias: {
...config.resolve.alias,
},
fallback: {
...config.resolve.fallback,
fs: false,
stream: false,
constants: false,
assert: false,
util: false,
},
},
};
},
Seems to be working for me for now. Thanks for this thread. However, what would be the official way of doing it?
@jenniredfield it works because you're using the old version 1.0.19 with which it's expected to work. Does it continue to work if you upgrade to 1.1.2?
I had the plugin-cloud-storage 1.1.3 installed for quite some time (since a month) and never ran into the issue (while also never upgrading anything since a month).
But today I suddenly have the issue, but only in my builds (build -> serve -> ui crashes with bug) never in dev.
Even if I checkout previous versions of my repo, from when I never had the issue, it suddenly always builds with this strange bug.
I made sure to always delete my node_modules
directory after checking out different versions but the bug persists and I simply can't explain it to myself why my setup hadn't shown the bug until now and suddenly does.
Then again, downgrading the plugin to 1.0.19 works as advertised.
And it really is a shame that my main.js
is currently at 6MB ... looking forward to that stable 3.0 without all those nodejs packages in the frontend :+1:
Link to reproduction
No response
Describe the Bug
When updating @payloadcms/plugin-cloud-storage from 1.0.19 to 1.1.2, I start getting the following error in the console:
From what I've seen, that error happens in the homedir-polyfill package. It's essentially because Node.js code ends up in the front-end bundle, where
process
is obviously not available. Similar to #4215.To Reproduce
Payload Version
2.9.0
Adapters and Plugins
plugin-cloud-storage