Apologies in advance if this isn't the right way to report this. However, while trying to run this as a node.js app on a web server I kept receiving the following error message...
const stripJsonComments = require('strip-json-comments');
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /public_html/wp-content/plugins/tickera-wallet-passes/pass-converter/node_modules/strip-json-comments/index.js from /public_html/wp-content/plugins/tickera-wallet-passes/pass-converter/config.js not supported.
Instead change the require of index.js in /public_html/wp-content/plugins/tickera-wallet-passes/pass-converter/config.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/public_html/wp-content/plugins/tickera-wallet-passes/pass-converter/config.js:17:27)
at Object.<anonymous> (/public_html/wp-content/plugins/tickera-wallet-passes/pass-converter/pass/index.js:27:16)
at Object.<anonymous> (/public_html/wp-content/plugins/tickera-wallet-passes/pass-converter/app.js:20:14) {
code: 'ERR_REQUIRE_ESM'
}
In case anyone else comes across this, I was able to fix it by using jsonc-parser instead of strip-json-comments since it is CommonJS-compatible. I also removed strip-json-trailing-commas sincejsonc-parser can handle JSON with comments and doesn't require stripping trailing commas separately. Not sure this is a proper fix or not, but it worked for me at least.
Change the config.js file to be:
const { parse } = require('jsonc-parser');
const fs = require('fs');
const path = require('path');
// The Proxy wrapper ensures config is lazily loaded, so we can redefine
// PASS_CONVERTER_CONFIG_PATH at runtime, which we do in the tests.
module.exports = new Proxy(
{},
{
get(target, prop, receiver) {
if (this._config === undefined) {
const configPath = process.env.PASS_CONVERTER_CONFIG_PATH || path.resolve(__dirname, 'config.json');
const configContent = fs.readFileSync(configPath, 'utf8'); // Ensure content is a string
// Parse the JSON content with comments handled by jsonc-parser
this._config = parse(configContent);
// Most of the entries default to empty strings, but code may expect them to be
// undefined since they were originally env vars, so filter these out to retain the behavior.
this._config = Object.fromEntries(Object.entries(this._config).filter(([key, value]) => value !== ''));
}
return this._config[prop];
},
},
);
Apologies in advance if this isn't the right way to report this. However, while trying to run this as a node.js app on a web server I kept receiving the following error message...
In case anyone else comes across this, I was able to fix it by using
jsonc-parser
instead ofstrip-json-comments
since it is CommonJS-compatible. I also removedstrip-json-trailing-commas
sincejsonc-parser
can handle JSON with comments and doesn't require stripping trailing commas separately. Not sure this is a proper fix or not, but it worked for me at least.Change the config.js file to be:
Change the package.json file to be: