[vite 3.0.0-alpha.5+] Cannot define
with stringified object value #8593
Closed
Description
Describe the bug
Starting in alpha.5, it's no longer possible to have a config like:
export default defineConfig({
define: {
foo: JSON.stringify({ foo: true }),
},
});
During build (but not dev), it will throw an error like:
Unexpected token (Note that you need plugins to import files that are not JavaScript)
file: /home/projects/vitejs-vite-bjukr5/node_modules/.vite/depsBuild/chunk-UC5OZ2ED.js?v=cf0d5223:11:13
9: // <define:foo>
10: var init_define_foo = __esm({
11: "<define:foo>"() {
^
12: }
13: });
error during build:
Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
at error (file:///home/projects/vitejs-vite-bjukr5/node_modules/rollup/dist/es/shared/rollup.js:1888:30)
at Module.error (file:///home/projects/vitejs-vite-bjukr5/node_modules/rollup/dist/es/shared/rollup.js:12452:16)
at Module.tryParse (file:///home/projects/vitejs-vite-bjukr5/node_modules/rollup/dist/es/shared/rollup.js:12829:25)
at Module.setSource (file:///home/projects/vitejs-vite-bjukr5/node_modules/rollup/dist/es/shared/rollup.js:12734:24)
at ModuleLoader.addModuleSource (file:///home/projects/vitejs-vite-bjukr5/node_modules/rollup/dist/es/shared/rollup.js:22208:20)
This is currently what's breaking the storybook vite-builder in vite 3.
Reproduction
https://stackblitz.com/edit/vitejs-vite-bjukr5?file=package.json
System Info
n/a
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- 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 https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.