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
I have a monorepo I'm trying to port to Vite from Rollup. I have a Rollup banner that imports its local package.json to introspect the name and version of the package it's bundling.
If I hardcode a path, Vite will accept the config:
const{ name, version }=awaitimport('./package.json',{assert: {type: 'json'},});
I spent all day trying to figure out what was wrong here. ERR_IMPORT_ASSERTION_TYPE_MISSING didn't come up in search, so I'm opening a new issue to help others find it. This is potentially related to #10460, which describes a problem using dynamic import from config files, but doesn't specify the error message, and doesn't appear to be importing JSON.
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.
Looks like esbuild strips it off (evanw/esbuild#2036) as we bundle the config file to a specific node version in Vite 4 (node14.8 & node16). But this should be fixed in Vite 5 as we set it to node18.
Describe the bug
I have a monorepo I'm trying to port to Vite from Rollup. I have a Rollup banner that imports its local
package.json
to introspect thename
andversion
of the package it's bundling.When I try to use it from
vite.config.js
:Vite throws
This is what worked with Rollup and Node:
Ported to Node's implementation of type annotations, it looks like this:
and still fails in Vite, despite the error message.
Note: the assertion key is now
with
, but Node/Vite will reject that for having the wrong key.https://github.com/tc39/proposal-import-attributes
If I hardcode a path, Vite will accept the config:
I spent all day trying to figure out what was wrong here.
ERR_IMPORT_ASSERTION_TYPE_MISSING
didn't come up in search, so I'm opening a new issue to help others find it. This is potentially related to #10460, which describes a problem using dynamic import from config files, but doesn't specify the error message, and doesn't appear to be importing JSON.Reproduction
https://stackblitz.com/edit/vitejs-vite-mh4xpw?file=vite.config.js,createPackageBanner.mjs&terminal=dev
Steps to reproduce
import(path)
inside avite.config.js
file wherepath
includes a function call or template string that resolves to a.json
vite serve
System Info
System: OS: macOS 14.0 CPU: (8) arm64 Apple M1 Pro Memory: 56.73 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 20.9.0 - /private/var/folders/p0/kbnclsq57q96dg1kd3699mvc00_vh7/T/xfs-94e69998/node Yarn: 4.0.0 - /private/var/folders/p0/kbnclsq57q96dg1kd3699mvc00_vh7/T/xfs-94e69998/yarn npm: 10.1.0 - ~/.nvm/versions/node/v20.9.0/bin/npm Browsers: Chrome: 118.0.5993.117 Chrome Canary: 120.0.6099.2 Safari: 17.0
Used Package Manager
yarn
Logs
Click to expand!
Validations
The text was updated successfully, but these errors were encountered: