Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Is it possible to alias server-only modules in Plugins?

default discord avatar
brachypelma8242 years ago
6

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.

  • default discord avatar
    paulpopus2 years ago

    Aliasing works for plugins too, are you able to share the plugin code?

  • default discord avatar
    brachypelma8242 years ago

    Let me see if I can quickly put together a small reproducible example

  • default discord avatar
    paulpopus2 years ago

    Actually have you looked into other examples (mine)

    https://github.com/NouanceLabs/payload-dashboard-analytics

    payload team has this one too:


    https://github.com/payloadcms/plugin-stripe

    You can see how both modules handle server aliasing

  • default discord avatar
    brachypelma8242 years ago

    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.

  • default discord avatar
    paulpopus2 years ago

    Glad it's resolved!

  • default discord avatar
    brachypelma8242 years ago

    Me too. Thank you for your help.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.