firestore-rulez icon indicating copy to clipboard operation
firestore-rulez copied to clipboard

ESM Support

Open christophe-g opened this issue 7 months ago • 0 comments

Hey - thanks a lot for this useful repo!

When using it in ESM context (e.g. within a project with type: "module" in package.json ), the rules fail to compile with and ERR_REQUIRE_ESM error.

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/christophe/Programming/Polymer/preignition/rulez.config.js from /home/christophe/Programming/Polymer/preignition/node_modules/.pnpm/[email protected]/node_modules/firestore-rulez/src/getConfig.js not supported.
rulez.config.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename rulez.config.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /home/christophe/Programming/Polymer/preignition/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at getConfig (/home/christophe/Programming/Polymer/preignition/node_modules/.pnpm/[email protected]/node_modules/firestore-rulez/src/getConfig.js:111:19)
    at compileFirestoreRules (/home/christophe/Programming/Polymer/preignition/node_modules/.pnpm/[email protected]/node_modules/firestore-rulez/src/index.js:23:46)
    at Object.<anonymous> (/home/christophe/Programming/Polymer/preignition/node_modules/.pnpm/[email protected]/node_modules/firestore-rulez/src/index.js:117:1) {
  code: 'ERR_REQUIRE_ESM'
}

christophe-g avatar Jan 17 '24 09:01 christophe-g