Bot Error: "Dynamic require of "@medplum/core" is ...
# support
z
Creating a thread dedicated to this issue as it seemed to be abandoned in [another thread](https://discord.com/channels/905144809105260605/1435933404507144234/1436244241327329291). After upgrading to v5, I started getting this error for all my bots:
Copy code
json
{
    "resourceType": "OperationOutcome",
    "issue": [
        {
            "severity": "error",
            "code": "invalid",
            "details": {
                "text": "Dynamic require of \"@medplum/core\" is not supported"
            }
        }
    ]
}
As of 5.0.4, a recent change to some example projects (I tested
examples/medplum-scheduling-demo
) switched to ESM for building the bots. I made the change to my project to see if that would fix it, but I'm getting an error with that too for both my project and the example project:
Copy code
json
{
    "resourceType": "OperationOutcome",
    "issue": [
        {
            "severity": "error",
            "code": "invalid",
            "details": {
                "text": "Cannot use import statement outside a module"
            }
        }
    ]
}
Since the example project ("project" as in code workspace) is failing, it leads me to believe something is wrong with the settings of the Medplum project stored in my database, since I pointed both code projects at that. My server is running the latest Docker image as of today (2025-11-24). My project dependencies are all 5.0.4.
f
Hi @Zira , is your Bot runtime set to AWS Lambda or VM Contet?
z
Hi there, it's set to
vmcontext
f
Hey @Zira we are investigating an issue right now with some changes we made to switch to ESM which is causing problems for vmcontext Bots
z
Thanks for your response! Okay, I'll stand by for any updates. I did some investigating and found that in the file that executes the vmcontext bot code, there's a line that defines the context's
require
as the global
require
if it exists, else
createRequire
. Though I believe with ESBuild,
require
always exists? I looked at the server's
dist/index.js
that was generated by ESBuild and found that if I commented out the
__require
line at the top, my CJS bot code started running. So I can use that as a workaround for now. I think if the goal is to transition bots to ESM, node:vm has a whole Modules paradigm that isn't currently used in the vmcontext execution file
i
@Zira , we have a fix coming for this - https://github.com/medplum/medplum/pull/7923
One thing to note, ESM won't work for vmcontext bots
z
Thank you! And noted 🙂
56 Views