payload-cloud-storage Cannot find module fs

default discord avatar
zinox9
3 months ago
28

I am getting this error when using the package.

  • discord user avatar
    alessiogr
    Payload Team
    3 months ago

    Yep, we're aware of this issue! Happens when conditionally enabling the plugin. Check out

    https://github.com/payloadcms/plugin-cloud-storage/issues/54

    where it's being tracked.


    Original discussion is here:

    https://discord.com/channels/967097582721572934/1102878160544079983/1116782409002799175


    Best thing you can do for now is manually include the alias in your webpack config or make sure that the cloud storage plugin is always enabled

  • default discord avatar
    zinox9
    3 months ago

    can you guide me how to make the cloud-storage-plugin to be always enable ?

  • discord user avatar
    alessiogr
    Payload Team
    3 months ago

    Pretty much just make sure the cloud plugin is always added to your plugins array in your payload config!



    Could you share the payload config you currently use where you're getting that error?

  • default discord avatar
    zinox9
    3 months ago
    export default buildConfig({
      serverURL: 'http://localhost:3000',
      admin: {
        user: Users.slug,
        buildPath: path.resolve(process.cwd(), 'build/'),
      },
      collections: [
        Users,
        Logs,
        VehicleInfos,
        Projects
      ],
      typescript: {
        outputFile: path.resolve(__dirname, 'payload-types.ts'),
      },
      graphQL: {
        schemaOutputFile: path.resolve(__dirname, 'generated-schema.graphql'),
      },
      plugins: [
        // Pass the plugin to Payload
        cloudStorage({
          collections: {
            // Enable cloud storage for Media collection
            media: {
              // Create the S3 adapter
              adapter: s3Adapter({
                config: {
                  endpoint: process.env.S3_ENDPOINT,
                  credentials: {
                    accessKeyId: process.env.S3_ACCESS_KEY_ID,
                    secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
                  },
                },
                bucket: process.env.S3_BUCKET,
              }),
            },
          },
        }),
      ], 
    });
  • discord user avatar
    alessiogr
    Payload Team
    3 months ago

    hmm strange. @denolfe check this out, seems it still happens despite it not being enabled conditionally

  • default discord avatar
    paulpopus
    3 months ago

    Is this happening with this very same config after you've deleted node_modules and installed it again?



    Wondering if webpack cached the previous webpack config 🤔

  • default discord avatar
    zinox9
    3 months ago

    Yep still getting the error , also tried using npm instead of yarn just in case that might work. But that also didnt.

  • discord user avatar
    denolfe
    Payload Team
    3 months ago
    The issue is due to conditionally enabling the plugin. If you include the plugin code at all, regardless of whether you put it into your plugins array, the webpack aliasing still needs to run.

    TLDR above ☝️ I'm working on a proper way to conditionally enable this plugin against this issue:

    https://github.com/payloadcms/plugin-cloud-storage/issues/54

    PR soon

  • discord user avatar
    alessiogr
    Payload Team
    3 months ago

    The thing here is, judging from the code he shared, he wasn't conditionally enabling the plugin and still got the error

  • discord user avatar
    denolfe
    Payload Team
    3 months ago

    Interesting, yeah I didn't read your comment well 😅

  • default discord avatar
    olarssony
    3 months ago

    im having the same problem, im also not condtionally including the plugin



    this may have something to do with webpack and its trying to include fs on the client-side, its what i suspect, but im not sure

  • discord user avatar
    denolfe
    Payload Team
    3 months ago

    @olarssony @zinox9 I made a few small adjustments on the webpack config in 1.0.17. Can you give that a try and see if the behavior is any different?

  • default discord avatar
    oloflarsson
    3 months ago

    Will check it out tomorrow at work!

  • default discord avatar
    zinox9
    3 months ago

    Deleted node_modules and upgraded and checked , still the same issue here 🧐

  • discord user avatar
    denolfe
    Payload Team
    3 months ago

    I loaded up your config (with different collections), and I'm able to build without any webpack issue. Not sure what could be going on here 🤔



    Oh, I think I may know what it is



    You have your plugin looking for a collection slug of

    media

    . Does this collection slug exist? Your collections don't look like they have something that would have a slug of media.



    collections: [Users, Logs, VehicleInfos, Projects],

    Do any of these have a collection slug of

    media

    ? This should correspond with a collection with uploads enabled.

  • default discord avatar
    zinox9
    3 months ago

    oh I see, I didnt notice we can specify the collection specifically here. I will try it out again and see if it works.



    Yep, Its working fine now. Thanks for the help !



    The Setup looked like it was a default structure and I didn't notice that we were specifying the collections from our end. My bad 😅

  • discord user avatar
    denolfe
    Payload Team
    3 months ago

    All good, we should probably validate if the slug is valid. There wasn't a very helpful error.

  • default discord avatar
    oloflarsson
    3 months ago

    Id be surprised if this was the problem for me, but ill check once i have thr code in front of me again

  • default discord avatar
    olarssony
    3 months ago

    this seems to have done it for me, uploading media to the cloud now works again. thx!

  • discord user avatar
    denolfe
    Payload Team
    3 months ago

    Amazing 🙌

Open the post
Continue the discussion in Discord
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.