Skip to content

vite.define doesn't work when a style tag is present #2497

New issue

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

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

Already on GitHub? Sign in to your account

Closed
illright opened this issue Sep 25, 2021 · 1 comment
Closed

vite.define doesn't work when a style tag is present #2497

illright opened this issue Sep 25, 2021 · 1 comment

Comments

@illright
Copy link
Contributor

Describe the bug

Normally, vite.define allows you to specify constant replacements for tokens in source code.

For some reason, whenever there's a non-empty style tag present in the file which is to undergo replacement, the page fails with a syntax error.

Reproduction

https://github.com/illright/sveltekit-bug-vite-define

This commit is what sets this repository apart from a regular skeleton app created with create-svelte@next.

Logs

10:42:02 PM [vite-plugin-svelte] /home/illright/work/sveltekit-bug-vite-define/src/routes/index.svelte:1:16 'vite' is not defined. Consider adding a <script> block with 'export let vite' to declare a prop
Unexpected token (6:118)
SyntaxError: Unexpected token (6:118)
    at Object.pp$5.raise (/home/illright/work/sveltekit-bug-vite-define/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-36bf480c.js:47485:13)
    at Object.pp.unexpected (/home/illright/work/sveltekit-bug-vite-define/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-36bf480c.js:44810:8)
    at Object.pp.expect (/home/illright/work/sveltekit-bug-vite-define/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-36bf480c.js:44804:26)
    at Object.pp$4.parseObj (/home/illright/work/sveltekit-bug-vite-define/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-36bf480c.js:47097:12)
    at Object.pp$4.parseExprAtom (/home/illright/work/sveltekit-bug-vite-define/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-36bf480c.js:46836:17)
    at Object.pp$4.parseExprSubscripts (/home/illright/work/sveltekit-bug-vite-define/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-36bf480c.js:46652:19)
    at Object.pp$4.parseMaybeUnary (/home/illright/work/sveltekit-bug-vite-define/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-36bf480c.js:46618:17)
    at Object.parseMaybeUnary (/home/illright/work/sveltekit-bug-vite-define/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-36bf480c.js:49793:29)
    at Object.pp$4.parseExprOps (/home/illright/work/sveltekit-bug-vite-define/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-36bf480c.js:46551:19)
    at Object.pp$4.parseMaybeConditional (/home/illright/work/sveltekit-bug-vite-define/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-36bf480c.js:46534:19)

System Info

System:
    OS: Linux 5.14 Manjaro Linux
    CPU: (8) x64 Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
    Memory: 881.21 MB / 7.62 GB
    Container: Yes
    Shell: 3.3.1 - /usr/bin/fish
  Binaries:
    Node: 16.10.0 - /usr/bin/node
    Yarn: 1.22.11 - /usr/bin/yarn
    npm: 7.24.1 - /usr/bin/npm
  Browsers:
    Firefox: 92.0.1
  npmPackages:
    @sveltejs/kit: next => 1.0.0-next.174 
    svelte: ^3.42.6 => 3.43.0

Severity

blocking all usage of SvelteKit

Additional Information

This particularly happens in SvelteKit – when I tried to reproduce the bug with a regular Svelte + Vite app created by create-vite, everything worked out well.

@bluwy
Copy link
Member

bluwy commented Sep 26, 2021

Duplicate of #720. We're aware of this issue currently and have a plan to solve it. Will be tracking the progress there instead.

@bluwy bluwy closed this as completed Sep 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants