-
-
Notifications
You must be signed in to change notification settings - Fork 8k
ssrTransform fails to transform import.meta when there is imported variable named meta #22004
Copy link
Copy link
Closed
Bug
Copy link
Labels
feat: ssrp3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)
Description
Describe the bug
ssrTransform fails to transform code below:
import { meta } from './meta';
console.log(import.meta.url, `Hello, ${meta}!`);Error message
Error: Cannot split a chunk that has already been edited (1:19 – "import.meta")
at MagicString._splitChunk (file:///home/projects/vitejs-vite-5acvpgpu/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/node.js:4738:10)
at MagicString._split (file:///home/projects/vitejs-vite-5acvpgpu/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/node.js:4729:43)
at MagicString.update (file:///home/projects/vitejs-vite-5acvpgpu/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/node.js:4553:8)
at onIdentifier (file:///home/projects/vitejs-vite-5acvpgpu/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/node.js:11324:75)
at eval (file:///home/projects/vitejs-vite-5acvpgpu/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/node.js:11436:37)
at walk (file:///home/projects/vitejs-vite-5acvpgpu/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/node.js:11435:14)
at ssrTransformScript (file:///home/projects/vitejs-vite-5acvpgpu/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/node.js:11301:2)
at async loadAndTransform (file:///home/projects/vitejs-vite-5acvpgpu/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/node.js:24317:64)
Looks like it hits the below s.update(id.start, id.end, binding) call and tries to replace meta in import.meta with something else. Need to handle a MetaProperty parent.
| s.update(id.start, id.end, binding) |
For context, I encountered this bug while using Storybook Vitest addon.
Reproduction
Steps to reproduce
vite.config.ts:
import { defineConfig } from "vite";
export default defineConfig({
environments: {
ssr: {},
},
builder: {
async buildApp() { }
}
})repro.ts:
import { createServer } from "vite"
const server = await createServer()
const result = await server.environments.ssr.transformRequest("src/index.ts");
console.log(result?.code);
await server.close();src/index.ts:
import { meta } from './meta';
console.log(import.meta.url, `Hello, ${meta}!`);Run node repro.ts to see the error.
System Info
Both Vite 7 and 8 have this issue.
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 22.22.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.8.2 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpmUsed 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 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
feat: ssrp3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)