Iām running into problem trying to upgrade to new versions of Parse Server. If I run Parse Server 7.1.0, everything works correctly. However, after upgrading to either 7.2.0 or 7.3.0, I get this error:
require() of ES Module /node_modules/@parse/push-adapter/src/index.js from /index.js not supported. Instead change the require of /node_modules/@parse/push-adapter/src/index.js in /index.js to a dynamic import() which is available in all CommonJS modules.
If I add ātypeā: āmoduleā to my package.json file, I should be able to successfully import the push-adapter, but that makes it so that ārequireā no longer works, and thatās used extensively throughout the project. The Git page for the push adapter says this:
// For CommonJS replace the import statemtent above with the following line:
// const ParsePushAdapter = require(ā@parse/push-adapterā).default;
And this is how I have been instantiating the push adapter for several years. Now Iām no longer able to do so. Is there something simply Iām missing here? Is there a way I can get the push adapter imported using ārequireā when running Parse Server 7.3.0?
Iām coming back to this issue after a few months, because the error is still being thrown when attempting to upgrade to parse-server > 7.1.0. Does anyone know why ārequire(ā@parse/push-adapterā).defaultā isnāt working in my environment? To reiterate, if I downgrade to parse-server 7.1, the code Iāve been working with for years that imports the push adapter with the ārequireā statement" woks as it should. The error only happens when I attempt to upgrade parse-server. Any help would be much appreciated.
After more searching and troubleshooting, I believe I have the solution. First, the right, or proper, solution is to update all my project to ESM logic so as to use āimportā for all of my included modules in all scripts. That option isnāt possible for me right now since it would take quite a lot of time and testing to make sure there are no problems throughout the Cloud Code. I will do this eventually, but not now.
The workaround Iāve found is to use an async IIFE to wrap all my config code in our index.js file. Inside the IIFE, I can then use this expression to import the push adapter:
const { default: PushAdapter } = await import('@parse/push-adapter')
If there is something wrong with this approach, please let me know. Thank you everyone!