When using an object property in a media query, as const
in the object definition causes build to fail
#1628
Labels
bug 🐛
Something isn't working
The following code fails with a
Cannot statically evaluate the value of "MemberExpression
error:Removing
as const
resolves the error.This is because
@compiled/babel-plugin
is not able to handle theTSAsExpression
node when traversing the Babel AST.TSAsExpression
is the node Babel uses to represent the{ ... } as const
syntax.Note that
as const
can appear anywhere in an object, so we need to handle stuff like this too:These are the files that need to be updated to support the
{ ... } as const
syntax (there might be more):compiled/packages/babel-plugin/src/utils/traverse-expression/traverse-member-expression/traverse-access-path/evaluate-path/index.ts
Line 14 in 5a5ab2e
compiled/packages/babel-plugin/src/utils/traversers/object.ts
Line 6 in 41bcb1e
Workaround
You can try using
readonly
instead ofas const
. It's kind of awkward for large variables, but it avoids the errors:The text was updated successfully, but these errors were encountered: