Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.0.0 Upgrade Plugin #3358

Closed
zachleat opened this issue Jul 10, 2024 · 4 comments
Closed

v3.0.0 Upgrade Plugin #3358

zachleat opened this issue Jul 10, 2024 · 4 comments

Comments

@zachleat
Copy link
Member

https://github.com/11ty/eleventy-upgrade-help

@zachleat zachleat added this to the Eleventy 3.0.0 milestone Jul 10, 2024
zachleat added a commit to 11ty/eleventy-upgrade-help that referenced this issue Jul 23, 2024
@zachleat
Copy link
Member Author

zachleat commented Jul 23, 2024

zachleat added a commit that referenced this issue Jul 24, 2024
…ror message for requiring Eleventy in a CommonJS project and will work as expected when this support is added natively too.
@zachleat
Copy link
Member Author

Future-friendly error message when you try to require("@11ty/eleventy") in 3.0.0-alpha.18 or newer. This will not be shown when using --experimental-require-module or when Node.js enables require of synchronous ESM by default.

> @11ty/[email protected] build
> npx @11ty/eleventy --quiet

[11ty] 1. Error in your Eleventy config file 'eleventy.config.js'. (via EleventyConfigError)
[11ty] 2. Eleventy cannot be loaded via `require("@11ty/eleventy")` in 3.0 and newer. Instead, you have a few options:
[11ty]    1. (Easiest) Change the `require` to use a dynamic import inside of an asynchronous CommonJS configuration callback, for example:
[11ty] 
[11ty]       module.exports = async function {
[11ty]         const {EleventyRenderPlugin, EleventyI18nPlugin, EleventyHtmlBasePlugin} = await import("@11ty/eleventy");
[11ty]       }
[11ty] 
[11ty]    2. (Easier) Update the JavaScript syntax in your configuration file from CommonJS to ESM (change `require` to `import` and rename the file to have an .mjs file extension).
[11ty]    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`.)
[11ty]    4. (Short term workaround) Use the --experimental-require-module flag to enable this behavior. Read more: https://nodejs.org/api/modules.html#loading-ecmascript-modules-using-require It is possible that the newest version of Node has this enabled by default—you can try upgrading your version of Node.js.

@zachleat
Copy link
Member Author

https://www.npmjs.com/package/@11ty/eleventy-upgrade-help v3.0.0 is now available on npm.

I’ve updated the demo project to use it as well: https://github.com/11ty/demo-eleventy-upgrade-help/

There are a few small improvements to core that will ship with 3.0.0-alpha.18 to improve error messaging on ESM and retired Serverless/Edge plugins and #3373 but everything else should work as-is with the newest published canary alpha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant