Problem using library 'basic-ftp'

default discord avatar
aljubaer
2 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?

  • discord user avatar
    jmikrut
    Payload Team
    2 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
    aljubaer
    2 years ago

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

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.