Directus site not deploying properly

I have a Directus site that I’ve deployed successfully lots of times in the last few months. This week, when I tried to deploy, the deployment hooks are all successful, but I’m getting this error:

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/cleavr/SITE_NAME/releases/20230503032853694/directus/node_modules/directus/cli.js not supported.
Instead change the require of cli.js in null to a dynamic import() which is available in all CommonJS modules.
    at /usr/lib/node_modules/pm2/lib/ProcessContainer.js:303:25
    at wrapper (/usr/lib/node_modules/pm2/node_modules/async/internal/once.js:12:16)
    at next (/usr/lib/node_modules/pm2/node_modules/async/waterfall.js:96:20)
    at /usr/lib/node_modules/pm2/node_modules/async/internal/onlyOnce.js:12:16
    at WriteStream.<anonymous> (/usr/lib/node_modules/pm2/lib/Utility.js:186:13)
    at WriteStream.emit (node:events:513:28)
    at FSReqCallback.oncomplete (node:fs:198:23)

I’ve updated Directus to the latest version (^10.0.0) in my codebase, and it appears to be using this version. It looks like pm2 is trying to require instead of import it. Here’s the relevant code in pm2:

    300     if (ProcessUtils.isESModule(script) === true)
    301       import(process.env.pm_exec_path);
    302     else
    303       require('module')._load(script, null, true);

Is there an upgrade to pm2 that I need to install? Why would pm2 not be reading this as a module?

Hello @sheffield ,

To ensure the safety of your database before updating the Directus version to 10.0.0, we strongly recommend taking a backup.

SSH into the server as a server user associated with the site, making sure not to SSH into the server as a root user, and run the following command. (See the attached screenshot to find the server user associated with your site.)

Once you SSH into the server, run the following command:

cd {{ webDirectory }}

webDirectory : You can get your site’s Web Directory from Server > Sites > Select site > Site Details . From the details page copy your site’s Web Directory . (See the attached screenshot to find Web Directory .)

Now open the package.json file and update it with the following configuration:

...
“type”:  “module”,
“dependencies”: {
	“directus”: “^10.0.0”
}
...

Once you’ve updated and saved the file, run the following commands one after another:

npm install
npx directus bootstrap
pm2 restart .cleavr.config.js

Your app should now be restarted and using the latest version of Directus. You can check the Updates & Migrations documentation from Directus (Upgrades & Migrations | Directus Docs) for more details.

Please keep in mind that you may run into other issues, and your production site may break. So, make sure to keep a backup of your database and find a way to restore it in case it is needed.

thanks for the quick and super helpful response. i’ll work through these and will update.

Looks like all I was missing was to add "type": "module" to my package.json file. Once I added that and pushed, it worked great. Thanks for the help!

3 Likes