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.

Problem using library 'basic-ftp'

default discord avatar
aljubaer3 years ago
1 1

This problem may not for Payload CMS. However, I want to use 'basic-ftp' library for connecting ftp client in payload. But when I am trying to import the library, it gives me the following error.

ERROR in ./node_modules/basic-ftp/dist/Client.js 4:13-26
Module not found: Error: Can't resolve 'fs' in 'C:\Users\BS0493\OneDrive\Desktop\practice-codes\Bronx server\node_modules\basic-ftp\dist'

ERROR in ./node_modules/basic-ftp/dist/Client.js 6:14-28
Module not found: Error: Can't resolve 'tls' in 'C:\Users\BS0493\OneDrive\Desktop\practice-codes\Bronx server\node_modules\basic-ftp\dist'

ERROR in ./node_modules/basic-ftp/dist/FtpContext.js 4:14-28
Module not found: Error: Can't resolve 'net' in 'C:\Users\BS0493\OneDrive\Desktop\practice-codes\Bronx server\node_modules\basic-ftp\dist'

ERROR in ./node_modules/basic-ftp/dist/StringWriter.js 4:17-34
Module not found: Error: Can't resolve 'stream' in 'C:\Users\BS0493\OneDrive\Desktop\practice-codes\Bronx server\node_modules\basic-ftp\dist'

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: { "stream": require.resolve("stream-browserify") }'
        - install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "stream": false }

ERROR in ./node_modules/basic-ftp/dist/netUtils.js 4:14-28
Module not found: Error: Can't resolve 'tls' in 'C:\Users\BS0493\OneDrive\Desktop\practice-codes\Bronx server\node_modules\basic-ftp\dist'

ERROR in ./node_modules/basic-ftp/dist/transfer.js 5:14-28
Module not found: Error: Can't resolve 'tls' in 'C:\Users\BS0493\OneDrive\Desktop\practice-codes\Bronx server\node_modules\basic-ftp\dist'

webpack compiled with 6 errors

It seems like a problem with webpack config. I found a lot of solutions, but nothing seems to work for me. Can anyone, how can I use 'basic-ftp' in payload cms?

  • Selected Answer
    discord user avatar
    jmikrut
    3 years ago

    Hey @aljubaer

    This is actually a common problem that has to do with importing non browser-friendly code into browser apps. As the Payload config is shared between the server and the browser, installing server-only modules like basic-ftp will allow the server to work fine, but cause the browser bundle to break.

    But - fixing it is easy! See here in the docs:
    https://payloadcms.com/docs/admin/webpack#aliasing-server-only-modules

    Also, I've written up a bit longer of a response to this type of issue in another discussion here:
    #205

    Does this help?

    1 reply
  • default discord avatar
    aljubaer3 years ago

    Yes, this works fine. Thank you for your reply.

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..