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

ESM throw a Error 'Dynamic require of "element-plus/package.json" is not supported' #194

Closed
liuzw2579 opened this issue Oct 28, 2021 · 3 comments · Fixed by #232
Closed
Assignees
Labels
bug Something isn't working

Comments

@liuzw2579
Copy link

in utils.ts function getPkgVersion use require to load 'package.json', but mjs file not have require

@sxzz
Copy link
Member

sxzz commented Oct 29, 2021

Could you please provide a minimum reproduction link?

@sxzz sxzz added the resolver label Oct 29, 2021
@sxzz sxzz self-assigned this Oct 29, 2021
@liuzw2579
Copy link
Author

liuzw2579 commented Oct 30, 2021

Could you please provide a minimum reproduction link?

When I create a vite plugin, package.json has type: module, it is a ESM pkg.
that plugin returns plugin array, include unplugin-vue-components and element-plus resolver. so, node will load unplugin-vue-components mjs file.
but src/core/utils.ts has code:
export function getPkgVersion(pkgName: string, defaultVersion: string): string { try { /* eslint-disable @typescript-eslint/no-var-requires */ return require(${pkgName}/package.json).version } catch (err) { console.error(err) return defaultVersion } }

@sxzz sxzz added bug Something isn't working pr welcome and removed needs reproduction resolver labels Oct 30, 2021
@sxzz sxzz changed the title ESM throw a Error 'Dynamic require of "element-plus/package.json" is not supported' from '/unplugin-vue-components/dist/chunk-PJJOEYQ7.mjs:26:9' ESM throw a Error 'Dynamic require of "element-plus/package.json" is not supported' Oct 30, 2021
@nabaonan
Copy link
Collaborator

nabaonan commented Dec 4, 2021

i start a pr use resolve method instead of require , #232

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants