Skip to content

chore(build)!: drop cjs api #2737

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

Merged
merged 3 commits into from
Aug 8, 2023
Merged

chore(build)!: drop cjs api #2737

merged 3 commits into from
Aug 8, 2023

Conversation

brc-dd
Copy link
Member

@brc-dd brc-dd commented Aug 6, 2023

BREAKING CHANGE!

Drops Node CJS API. It is recommended to use

import {} from vitepress

instead of

const {} = require('vitepress')

and "type": "module" at the nearest package.json or .mjs/.mts extension for defining config (or other files where vitepress' node API is being used).

Trying to use CJS build will yield error:

"vitepress" resolved to an ESM file. ESM file cannot be loaded by `require`. See http://vitejs.dev/guide/troubleshooting.html#this-package-is-esm-only for more details. [plugin externalize-deps]

...

  The plugin "externalize-deps" was triggered by this import

    .vitepress/config.js:1:281:
      1 │ ...foo/.vitepress/config.js";const __vite_injected_original_import_meta_url = "file:///Users/brc-dd/foo/.vitepress/config.js";import { defineConfig } from 'vitepress'
        ╵                                                                                                                                                            ~~~~~~~~~~~

failed to load config from /Users/brc-dd/foo/.vitepress/config.js

The link in the error message should be sufficient for resolving most cases. In case of any issues, post it in #2703 itself. That issue won't be locked.

closes #2703

attw results
"vitepress"

node10: 🟢 
node16 (from CJS): ⚠️ ESM (dynamic import only)
node16 (from ESM): 🟢 (ESM)
bundler: 🟢 

***********************************

"vitepress/package.json"

node10: 🟢 (JSON)
node16 (from CJS): 🟢 (JSON)
node16 (from ESM): 🟢 (JSON)
bundler: 🟢 (JSON)

***********************************

"vitepress/client"

node10: 🟢 
node16 (from CJS): ⚠️ ESM (dynamic import only)
node16 (from ESM): 🟢 (ESM)
bundler: 🟢 

***********************************

"vitepress/theme"

node10: 🟢 
node16 (from CJS): ⚠️ ESM (dynamic import only)
node16 (from ESM): 🟢 (ESM)
bundler: 🟢 

***********************************

"vitepress/theme-without-fonts"

node10: 🟢 
node16 (from CJS): ⚠️ ESM (dynamic import only)
node16 (from ESM): 🟢 (ESM)
bundler: 🟢 

***********************************

@brc-dd
Copy link
Member Author

brc-dd commented Aug 6, 2023

/cc @bluwy @benmccann

Copy link
Member

@userquin userquin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add migration guide in readme and/or docs

@brc-dd brc-dd merged commit 9df8adb into main Aug 8, 2023
@brc-dd brc-dd deleted the drop-cjs branch August 8, 2023 10:22
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Moving VitePress' Node API as ESM only
5 participants