Skip to content

import.meta.resolve detection fails when formatted across multiple lines by Prettier #21308

@ItaiYosephi

Description

@ItaiYosephi

Describe the bug

After upgrading Prettier, import.meta.resolve() calls in vite.config.ts get reformatted across multiple lines, causing the build to fail:

// Before (works)
import.meta.resolve('@some/package')

// After Prettier (broken)
import.meta
  .resolve('@some/package')

getting this error:

ReferenceError: __vite_injected_original_import_meta_resolve is note the expression when split across lines, so it fails to inject the resolver helper.

This appears related to #20326 which was fixed in #20962, but that fix doesn't handle the case where formatters break the expression across lines.

Reproduction

https://stackblitz.com/edit/vitejs-vite-1d7x8izq?file=vite.config.ts

Steps to reproduce

No response

System Info

System:
  OS: macOS 26.2
  CPU: (16) arm64 Apple M4 Max
  Memory: 4.52 GB / 64.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 24.11.0 - ~/.nvm/versions/node/v24.11.0/bin/node
  Yarn: 4.12.0 - ~/.nvm/versions/node/v24.11.0/bin/yarn
  npm: 11.6.1 - ~/.nvm/versions/node/v24.11.0/bin/npm
  bun: 1.3.4 - /opt/homebrew/bin/bun
Browsers:
  Chrome: 143.0.7499.110
  Firefox: 146.0
  Safari: 26.2
npmPackages:
  vite: ^7.2.6 => 7.2.6

Used Package Manager

yarn

Logs

No response

Validations

Metadata

Metadata

Labels

p3-minor-bugAn edge case that only affects very specific usage (priority)

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions