Skip to content

Commit

Permalink
feat(css): add friendly errors for IE hacks that are not supported by…
Browse files Browse the repository at this point in the history
… lightningcss (#19072)
  • Loading branch information
sapphi-red authored Jan 23, 2025
1 parent 8c24ee4 commit caad985
Showing 1 changed file with 19 additions and 0 deletions.
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 @@ -3243,6 +3243,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

0 comments on commit caad985

Please sign in to comment.