Closed NWYLZW closed 5 months ago
vite-plugin-glob-accept
plugin problem, "type": "module"
is not specified in package.json or name index.esm.js
into index.esm.mjs
.
vite-plugin-glob-accept
plugin problem,"type": "module"
is not specified in package.json or nameindex.esm.js
intoindex.esm.mjs
.
I feel there's a bit of an issue. Why is it that even after setting up exports
and module
, it still continues to load as CommonJS (CJS), resulting in the outside module problem?
I'll take another look at the specific standards and behavior. I feel that directly assuming a file with a .ts
extension to be ESM seems a bit strange.
Whether the module is resolved as ESM or CJS can be determined by the type field of package.json or the file suffix.
However, since Electron does not support ESM before version 28, using the type field of package.json to support configuration file parsing comes at a cost. Of course, electron-vite is supported, but we cannot force developers to choose this option, and vite has such a requirement. On the other hand, most plugin distributions for Vite or Rollup are released as ESM, so it is intentional to parse ts configuration files into ESM.
In fact, there is an issue with the release of this plugin vite-plugin-glob-accept
. If the configuration file suffix is changed to mts or mjs, this error will also occur. The reason has been mentioned earlier. Of course, if you change the configuration file to cts, there is no problem.
Directly using vite.config.ts seems to be fine.
Directly using vite.config.ts seems to be fine.
this way will use commonjs
module. Try to add "type": "module"
to your package.json
will get the error.
You are right.
Describe the bug
https://github.com/alex8088/electron-vite/blob/1838bdbf3ee91e5a0cd39840190ad2506edfd583/src/utils.ts#L78
Remove ts extension check, it can't be load esm when use ts extension.
Electron-Vite Version
2.2.0
Electron Version
28.2.0
Vite Version
5.0.12
Validations