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