Better support for `type: "module"` from user
See original GitHub issueIs your feature request related to a problem? Please describe.
The outputs ESM entries are not fully compatible with native ESM actually, take the following as example
https://unpkg.com/browse/vitepress@1.0.0-alpha.4/dist/client/index.js
All relative file paths should be ended with correct .js
extension, and /index.js
can not be omitted anymore.
That’s being said, we should use moduleResolution: "Node16"
instead.
And when the user enables type: "module"
in their package.json
or .vitepress/package.json
, all temporary .js
files in .vitepress/.temp
would be considered as ESM only, and now it would emit error:
vitepress v1.0.0-alpha.4
- building client + server bundles...
@alauda/chart doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have "type": "module" or an .mjs extension for the entry point). Please contact the package author to fix.
quill-image-uploader doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have "type": "module" or an .mjs extension for the entry point). Please contact the package author to fix.
✓ building client + server bundles...
- rendering pages...
✖ rendering pages...
build error:
ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/home/jenkins/agent/workspace/frontend/frontend-vision-docs/docs/.vitepress/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///home/jenkins/agent/workspace/frontend/frontend-vision-docs/docs/.vitepress/.temp/app.js:2:25
at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
at async renderPage (file:///home/jenkins/agent/workspace/frontend/frontend-vision-docs/node_modules/vitepress/dist/node/serve-05342c3d.js:39534:25)
at async build (file:///home/jenkins/agent/workspace/frontend/frontend-vision-docs/node_modules/vitepress/dist/node/serve-05342c3d.js:39853:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
script returned exit code 1
Describe the solution you’d like
Enable moduleResolution: "Node16"
and add a package.json
into .vitepress/.temp
with type: "commonjs"
for now, and migrate all outputs files as pure ESM later.
Describe alternatives you’ve considered
We can use .cjs
files extensions for files outputs in .vitepress/.temp
Additional context
Validations
- Follow our Code of Conduct
- Read the docs.
- Read the Contributing Guidelines.
- Check that there isn’t already an issue that asks for the same feature to avoid creating a duplicate.
Issue Analytics
- State:
- Created a year ago
- Comments:22 (19 by maintainers)
@brc-dd See #1136
OK, I’ll add it locally and manually.