Skip to content
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

feat(css): add friendly errors for IE hacks that are not supported by lightningcss #19072

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3227,6 +3227,25 @@ async function compileLightningCSS(
line: e.loc.line,
column: e.loc.column - 1, // 1-based
}
// add friendly error for https://github.com/parcel-bundler/lightningcss/issues/39
try {
const code = fs.readFileSync(e.fileName, 'utf-8')
const commonIeMessage =
', which was used in the past to support old Internet Explorer versions.' +
' This is not a valid CSS syntax and will be ignored by modern browsers. ' +
'\nWhile this is not supported by LightningCSS, you can set `css.lightningcss.errorRecovery: true` to strip these codes.'
if (/[\s;{]\*[a-zA-Z-][\w-]+\s*:/.test(code)) {
// https://stackoverflow.com/a/1667560
e.message +=
'.\nThis file contains star property hack (e.g. `*zoom`)' +
commonIeMessage
} else if (/min-width:\s*0\\0/.test(code)) {
// https://stackoverflow.com/a/14585820
e.message +=
'.\nThis file contains @media zero hack (e.g. `@media (min-width: 0\\0)`)' +
commonIeMessage
}
} catch {}
}
throw e
}
Expand Down
Loading