You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package.json with UTF-8 with BOM encoding is not parsed correctly in imported modules, both in dev and build modes. This is likely to happen when a package doesn't originate from npm registry.
This results in an obscure error when a package that contains such package.json fails to be imported:
error during build:
[vite]: Rollup failed to resolve import "bom" from ".../src/import-packages.mjs".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
at viteWarn (file:///.../node_modules/vite/dist/node/chunks/dep-yUJfKD1i.js:50728:17)
at onRollupWarning (file:///.../node_modules/vite/dist/node/chunks/dep-yUJfKD1i.js:50760:5)
at onwarn (file:///.../node_modules/vite/dist/node/chunks/dep-yUJfKD1i.js:50426:7)
at file:///.../node_modules/rollup/dist/es/shared/node-entry.js:19475:13
at Object.logger [as onLog] (file:///.../node_modules/rollup/dist/es/shared/node-entry.js:21201:9)
at ModuleLoader.handleInvalidResolvedId (file:///.../node_modules/rollup/dist/es/shared/node-entry.js:20090:26)
at file:///.../node_modules/rollup/dist/es/shared/node-entry.js:20048:26
at async Promise.all (index 1)
And more specific error when package directory is directly imported:
error during build:
[commonjs--resolver] Unexpected token '', "{
"exp"... is not valid JSON
at JSON.parse (<anonymous>)
at loadPackageData (file:///.../node_modules/vite/dist/node/chunks/dep-yUJfKD1i.js:9420:21)
at tryCleanFsResolve (file:///.../node_modules/vite/dist/node/chunks/dep-yUJfKD1i.js:16089:23)
at tryFsResolve (file:///.../node_modules/vite/dist/node/chunks/dep-yUJfKD1i.js:16037:15)
at Object.resolveId (file:///.../node_modules/vite/dist/node/chunks/dep-yUJfKD1i.js:15875:19)
at Object.handler (file:///.../node_modules/vite/dist/node/chunks/dep-yUJfKD1i.js:50806:15)
at file:///.../node_modules/rollup/dist/es/shared/node-entry.js:20812:40
at async PluginDriver.hookFirstAndGetPlugin (file:///.../node_modules/rollup/dist/es/shared/node-entry.js:20712:28)
at async resolveId (file:///.../node_modules/rollup/dist/es/shared/node-entry.js:19316:26)
at async ModuleLoader.resolveId (file:///.../node_modules/rollup/dist/es/shared/node-entry.js:19745:15)
Imported package.json without BOM is correctly processed by Vite under the same conditions.
package.json with BOM are correctly imported natively in Node, besides the inconsistencies between Node versions be caused by importing directories with ESM (ERR_UNSUPPORTED_DIR_IMPORT):
npm i
npx vite --config vite.config-packages.js build
npx vite --config vite.config-dirs.js build
npx vite --config vite.config-packages.js
npx vite --config vite.config-dirs.js
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
Describe the bug
package.json with UTF-8 with BOM encoding is not parsed correctly in imported modules, both in dev and build modes. This is likely to happen when a package doesn't originate from npm registry.
This results in an obscure error when a package that contains such package.json fails to be imported:
And more specific error when package directory is directly imported:
Imported package.json without BOM is correctly processed by Vite under the same conditions.
package.json with BOM are correctly imported natively in Node, besides the inconsistencies between Node versions be caused by importing directories with ESM (ERR_UNSUPPORTED_DIR_IMPORT):
Reproduction
https://github.com/bisubus/vite-package-json-utf8-demo
Steps to reproduce
npm i
npx vite --config vite.config-packages.js build
npx vite --config vite.config-dirs.js build
npx vite --config vite.config-packages.js
npx vite --config vite.config-dirs.js
System Info
Used Package Manager
npm
Logs
Validations
The text was updated successfully, but these errors were encountered: