diff options
| author | Shipwreckt <me@shipwreckt.co.uk> | 2025-10-31 20:02:14 +0000 |
|---|---|---|
| committer | Shipwreckt <me@shipwreckt.co.uk> | 2025-10-31 20:02:14 +0000 |
| commit | 7a52ddeba2a68388b544f529d2d92104420f77b0 (patch) | |
| tree | 15ddd47457a2cb4a96060747437d36474e4f6b4e /node_modules/@11ty/eleventy/src/EleventyCommonJs.cjs | |
| parent | 53d6ae2b5568437afa5e4995580a3fb679b7b91b (diff) | |
Changed from static to 11ty!
Diffstat (limited to 'node_modules/@11ty/eleventy/src/EleventyCommonJs.cjs')
| -rw-r--r-- | node_modules/@11ty/eleventy/src/EleventyCommonJs.cjs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/node_modules/@11ty/eleventy/src/EleventyCommonJs.cjs b/node_modules/@11ty/eleventy/src/EleventyCommonJs.cjs new file mode 100644 index 0000000..5227265 --- /dev/null +++ b/node_modules/@11ty/eleventy/src/EleventyCommonJs.cjs @@ -0,0 +1,43 @@ +function canRequireModules() { + // via --experimental-require-module or newer than Node 22 support when this flag is no longer necessary + try { + require("./Util/Objects/SampleModule.mjs"); + return true; + } catch(e) { + if(e.code === "ERR_REQUIRE_ESM") { + return false; + } + + // Rethrow if not an ESM require error. + throw e; + } +} + +if(!canRequireModules()) { + let error = new Error(`\`require("@11ty/eleventy")\` is incompatible with Eleventy v3 and this version of Node. You have a few options: + 1. (Easiest) Change the \`require\` to use a dynamic import inside of an asynchronous CommonJS configuration + callback, for example: + + module.exports = async function { + const {EleventyRenderPlugin, EleventyI18nPlugin, EleventyHtmlBasePlugin} = await import("@11ty/eleventy"); + } + + 2. (Easier) Update the JavaScript syntax in your configuration file from CommonJS to ESM (change \`require\` + to use \`import\` and rename the file to have an \`.mjs\` file extension). + + 3. (More work) Change your project to use ESM-first by adding \`"type": "module"\` to your package.json. Any + \`.js\` will need to be ported to use ESM syntax (or renamed to \`.cjs\`.) + + 4. Upgrade your Node version (at time of writing, v22.12 or newer) to enable this behavior. If you use a version + of Node older than v22.12, try the --experimental-require-module command line flag in Node. Read more: + https://nodejs.org/api/modules.html#loading-ecmascript-modules-using-require`); + + error.skipOriginalStack = true; + + throw error; +} + +// If we made it here require(ESM) works fine (via --experimental-require-module or newer Node.js defaults) +let mod = require("./Eleventy.js"); + +module.exports = mod; |
