I am working on a plugin that includes a file that requires server-only modules. For now, I am just building it as a mock plugin in a plugins directory inside by Payload src directory. If I alias the file requiring server-only modules following the documented instructions, (
https://payloadcms.com/docs/admin/webpack#aliasing-server-only-modules) I still get compile errors. Interestingly, I can get everything to compile if I rework my plugin as a collection and load it in the collections aray (the plugin I am writing just adds a collection to the incoming config).
The fact that I can get this to work when I add my collection directly to the collections array but not when I add a plugin that does the same thing makes me wonder whether it is possible to use the documented aliasing technique in plugins. I'm afraid I don't understand what's going on under the hood clearly enough to understand why aliasing would work for collections but not plugins.
Aliasing works for plugins too, are you able to share the plugin code?
Let me see if I can quickly put together a small reproducible example
Actually have you looked into other examples (mine)
https://github.com/NouanceLabs/payload-dashboard-analyticspayload team has this one too:
You can see how both modules handle server aliasing
Thank you. Oddly enough, I was unable to reproduce the error in a simplified example. So I probably messed something up in my actual Payload instance. I will have to dig a bit deeper.
Ok, this is a bit embarrassing, but apparently the problem was the plugin name. I was calling it ImportExport. I know import and export are reserved keywords, but I thought writing them the way I did would be ok. When I changed the name to something else (DatabaseTransfer), I stopped getting compile errors.
Glad it's resolved!
Me too. Thank you for your help.
Star
Discord
online
Get dedicated engineering support directly from the Payload team.