facebook / docusaurus

Easy to maintain open source documentation websites.
https://docusaurus.io
MIT License
54.24k stars 8.13k forks source link

In version 2.1, the `npm run start` command breaks on Node 16 and 18 #8044

Closed LoicPoullain closed 1 year ago

LoicPoullain commented 1 year ago

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

Steps to reproduce: Use Node 16.14, 16.18 or 18.2 and run the following commands:

npx create-docusaurus@latest my-website classic
cd my-website
npm run start

We then get the following error:

[INFO] Starting the development server...
[ERROR] Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/loicpoullain/Desktop/my-website/node_modules/parse5/dist/cjs/index.js from /Users/loicpoullain/Desktop/my-website/node_modules/cheerio/lib/parsers/parse5-adapter.js not supported.
index.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 index.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 /Users/loicpoullain/Desktop/my-website/node_modules/parse5/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at Object.<anonymous> (/Users/loicpoullain/Desktop/my-website/node_modules/cheerio/lib/parsers/parse5-adapter.js:14:16)
    at Object.<anonymous> (/Users/loicpoullain/Desktop/my-website/node_modules/cheerio/lib/index.js:41:27)
    at Object.<anonymous> (/Users/loicpoullain/Desktop/my-website/node_modules/@docusaurus/plugin-content-blog/lib/feed.js:17:19)
    at Object.<anonymous> (/Users/loicpoullain/Desktop/my-website/node_modules/@docusaurus/plugin-content-blog/lib/index.js:17:16)
    at module.exports (/Users/loicpoullain/Desktop/my-website/node_modules/import-fresh/index.js:32:59)
    at normalizePluginConfig (/Users/loicpoullain/Desktop/my-website/node_modules/@docusaurus/core/lib/server/plugins/configs.js:45:57)
    at /Users/loicpoullain/Desktop/my-website/node_modules/@docusaurus/core/lib/server/plugins/configs.js:99:60
    at Array.map (<anonymous>)
    at loadPluginConfigs (/Users/loicpoullain/Desktop/my-website/node_modules/@docusaurus/core/lib/server/plugins/configs.js:99:38)
    at async initPlugins (/Users/loicpoullain/Desktop/my-website/node_modules/@docusaurus/core/lib/server/plugins/init.js:42:27)
    at async loadPlugins (/Users/loicpoullain/Desktop/my-website/node_modules/@docusaurus/core/lib/server/plugins/index.js:26:21)
    at async load (/Users/loicpoullain/Desktop/my-website/node_modules/@docusaurus/core/lib/server/index.js:76:58)
    at async Command.start (/Users/loicpoullain/Desktop/my-website/node_modules/@docusaurus/core/lib/commands/start.js:42:19)
[INFO] Docusaurus version: 2.1.0
Node version: v16.14.0

Reproducible demo

https://github.com/FoalTS/foal/tree/master/docs on branch "no-index-google"

Steps to reproduce

Use Node 16.14, 16.18 or 18.2 and run the following commands:

npx create-docusaurus@latest my-website classic
cd my-website
npm run start

Expected behavior

The command should succeed and start the server.

Actual behavior

The command prints this error:

[INFO] Starting the development server...
[ERROR] Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/loicpoullain/Desktop/my-website/node_modules/parse5/dist/cjs/index.js from /Users/loicpoullain/Desktop/my-website/node_modules/cheerio/lib/parsers/parse5-adapter.js not supported.
index.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 index.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 /Users/loicpoullain/Desktop/my-website/node_modules/parse5/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at Object.<anonymous> (/Users/loicpoullain/Desktop/my-website/node_modules/cheerio/lib/parsers/parse5-adapter.js:14:16)
    at Object.<anonymous> (/Users/loicpoullain/Desktop/my-website/node_modules/cheerio/lib/index.js:41:27)
    at Object.<anonymous> (/Users/loicpoullain/Desktop/my-website/node_modules/@docusaurus/plugin-content-blog/lib/feed.js:17:19)
    at Object.<anonymous> (/Users/loicpoullain/Desktop/my-website/node_modules/@docusaurus/plugin-content-blog/lib/index.js:17:16)
    at module.exports (/Users/loicpoullain/Desktop/my-website/node_modules/import-fresh/index.js:32:59)
    at normalizePluginConfig (/Users/loicpoullain/Desktop/my-website/node_modules/@docusaurus/core/lib/server/plugins/configs.js:45:57)
    at /Users/loicpoullain/Desktop/my-website/node_modules/@docusaurus/core/lib/server/plugins/configs.js:99:60
    at Array.map (<anonymous>)
    at loadPluginConfigs (/Users/loicpoullain/Desktop/my-website/node_modules/@docusaurus/core/lib/server/plugins/configs.js:99:38)
    at async initPlugins (/Users/loicpoullain/Desktop/my-website/node_modules/@docusaurus/core/lib/server/plugins/init.js:42:27)
    at async loadPlugins (/Users/loicpoullain/Desktop/my-website/node_modules/@docusaurus/core/lib/server/plugins/index.js:26:21)
    at async load (/Users/loicpoullain/Desktop/my-website/node_modules/@docusaurus/core/lib/server/index.js:76:58)
    at async Command.start (/Users/loicpoullain/Desktop/my-website/node_modules/@docusaurus/core/lib/commands/start.js:42:19)
[INFO] Docusaurus version: 2.1.0
Node version: v16.14.0

Your environment

Self-service

echarles commented 1 year ago

Same issue here.

echarles commented 1 year ago

parse5 7.0.0 has just been released and a fix is already out with https://github.com/inikulin/parse5/pull/664

This may help

Josh-Cena commented 1 year ago

Yep, this is entirely an external issue: package A is importing package B and it breaks. Docusaurus doesn't control either. You can pin your transitive dependencies, or upgrade them again.