Cannot find module 'ssh2-sftp-client': Medplum Bot...
# support
m
Hey there, hope everyone is doing well! For our upcoming project we need to write HL7 messages to a filesystem. As a proof of concept I am writing a Medplum Bot. I have a problem executing the Bot code in the vmcontext in a locally deployed Docker container (medplum/medplum-server:latest --> 4.3.3). I followed the tutorial "Bots in Production" https://www.medplum.com/docs/bots/bots-in-production and I successfully saved, deployed and executed a Hello World Bot with the Medplum CLI. When I add functionality with sftp like shown here https://www.medplum.com/docs/bots/file-uploads#sftp-uploads I get the error, when I execute the bot on the server: Error Cannot find module 'ssh2-sftp-client' Require stack: - /usr/src/medplum/packages/server/dist/bots/vmcontext.js - /usr/src/medplum/packages/server/dist/bots/execute.js - /usr/src/medplum/packages/server/dist/workers/cron.js ... This is surprising, because the docs state "Medplum Bots provide the ssh2-sftp-client library to connect to SFTP servers." I read this thread: https://linen.medplum.com/t/28489575/bots-with-imports-of-custom-code as well and I have the build script from the medplum-demo-bots in place to ensure the packaging is correct. Am I doing something wrong? Thanks very much in advance and all the best from Germany, Max
r
hey Max - di dyou build your bot from the command line and deploy it or use the in app editor?
m
Hey Reshma, thanks for quick reply. TL;DR: I tried it both ways, with the same result 😅: Error Cannot find module 'ssh2-sftp-client' 1: I wrote the bot code in my local code editor and then built it in the command line with
npm run build
. I created the bot in the webapp, because for the CLI it is Forbidden (see my message here: https://discord.com/channels/905144809105260605/1111343068390641776/1410614271611506699). From there I went back to the CLI, and saved and deployed the bot wit
npx medplum bot save
and
npx medplum bot deploy
. 2: Before that I also tried to create, save and deploy a bot with the
ssh2-sftp-client
dependency from within the webapp and the integrated code editor with the same result. Further details: You could use the sample bot-code from here to reproduce: https://github.com/medplum/medplum-demo-bots/blob/main/src/sftp-upload.ts The directory I use for the local coding of the bot is a clone of the
medplum-demo-bots
repo where I removed the existing bots from
src/
and
medplum.config.json
. I have Medplum deployed locally from
docker-compose.full-stack.yml
with no config changes. Thanks for your help, regards from Germany, Max
r
Hi @Max from m-creations thanks for reading out. This is a subtle difference between using vmcontext bots and lambda bots
We're working on closing this gap, but the root cause is that we manage bot dependencies slightly differently between Lambda bots and VMContext bots
* For VM Context Bots: We assume that all dependencies have been packaged with our Medplum server. * For lambda bots, we explicitly send a zip file with the dependencies pre-packaged
We're working on Fixing #1 so that our server has the sftp library as well
but if you'd like to try this on our hosted service with Lambda bots, that could be a way to unblock in the meantime
m
Hi @rahul1 thanks for the extensive reply and the offer to run the bot on your hosted service. And sorry for taking longer to reply back. TL;DR: I manually added the dependency to a local docker-build and I can now continue testing Medplum 🥰 , but the docs about SFTP-Uploads were misleading 🤔 . For our purposes we will not use the AWS platform and since our project will run on site I will have to get it running all locally. So if you could get the dependency packaged with the server that would be very much appreciated, especially because the docs state that it is packaged with the server: https://www.medplum.com/docs/bots/file-uploads#sftp-uploads (or they mislead me into believing that...). It took some figuring out to understand the problem because I could not reproduce the error running the code locally. Turns out that a cloned Medplum repo will have the dependency in its
node_modules
from the bot-layer dependencies, and thus the bot executes with the import of
ssh2-sftp-client
without a problem, when you run the server from source on your PC. After I understood that I just added the dependency to the server package and built a custom docker image locally. If there is any way I can help with the issue or the docs, please let me know. Thanks for your help and regards from Berlin, Max
98 Views