Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[vite 3.0.0-alpha.5+] Cannot define with stringified object value #8593

Closed
7 tasks done
IanVS opened this issue Jun 14, 2022 · 1 comment · Fixed by #8606
Closed
7 tasks done

[vite 3.0.0-alpha.5+] Cannot define with stringified object value #8593

IanVS opened this issue Jun 14, 2022 · 1 comment · Fixed by #8606
Labels
p4-important Violate documented behavior or significantly improves performance (priority)
Milestone

Comments

@IanVS
Copy link
Contributor

IanVS commented Jun 14, 2022

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

@bluwy
Copy link
Member

bluwy commented Jun 15, 2022

Seems to be caused by #8280 or #8281. I'm quite puzzled how this happens. When running npm run dev, you can see "<define:foo>"() { in one of the chunks in .vite/deps too

@bluwy bluwy added bug and removed pending triage labels Jun 15, 2022
@bluwy bluwy added this to the 3.0 milestone Jun 15, 2022
@sapphi-red sapphi-red added the p4-important Violate documented behavior or significantly improves performance (priority) label Jun 15, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jul 1, 2022
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
p4-important Violate documented behavior or significantly improves performance (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants