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

fix: ERR_REQUIRE_ESM error when project type is set to module #512

Closed
wants to merge 1 commit into from

Conversation

titouanmathis
Copy link

@titouanmathis titouanmathis commented Jan 31, 2022

There is currently a bug when building Vitepress in a project with its type set to module in the package.json file. The temporary directory for the SSR build is bundled in CJS format with .js extension. In a project whose type is set to module, these files are considered ESM and cannot be required(), see this reproduction repository to test the bug.

I was able to fix the issue by adding a package.json file in the temporary directory with type set to commonjs.

@brc-dd
Copy link
Member

brc-dd commented Jan 31, 2022

No it won't fix #476, although this PR might still be valid. That issue was about using ESM only packages like d3@7 with VitePress. Your PR doesn't fix that, it only fixes if someone is using CommonJS packages with VitePress but has type: module set in their package.json. Your change will throw a different error but it still won't work. Check brc-dd/vitepress-type-module-reproduction.

@titouanmathis
Copy link
Author

@brc-dd you are right, this does not fix #476, my bad. I updated the description to remove the mention of the issue.

@brc-dd
Copy link
Member

brc-dd commented Jul 1, 2022

closing this in favor of #856

@brc-dd brc-dd closed this Jul 1, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 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.

2 participants