Import a script to collection to use inside a hook

default discord avatar
vstarush
last year
1 1

Hello,

How do I import a script to a collection to use inside a hook? For example

/* collections > Product.js */

/* Importing someting*/
import { script } from "../utils/scripts";

/* Creating a collection */
const Product = {
    slug: 'products',
    ...
    hooks: {
        beforeChange: [
            async () => { script(); }
       ]
}

When I build this it builds ok, but when I am trying to access the admin panel it says in the console "webpack_require(...).config is not a function". And when I remove the imports, it works fine.

Any ideas how can I make this work?

Thank you!

  • default discord avatar
    vstarush
    last year

    Figured it out. Fixed it by changing "require" to "import" in the script.

Open the post
Continue the discussion in GitHub
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.