You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We expect this to work, because @compiled/babel-plugin runs a variety of functions specifically for resolving imported variables. However, we actually get a Cannot statically evaluate the value of "MemberExpression error.
This is because the function that finds exports in @atlaskit/primitives/responsive only looks for export statements in the form export { media } from './media-helper'; or perhaps export defaultExport from './test'. This fails with @atlaskit/primitives because there are no export statements to be found in the output, and so @compiled/babel-plugin cannot resolve the value of media.
We see in the above screenshot that what we expected to be export { media } from './media-helper' in TypeScript is in fact this boilerplate code in @atlaskit/primitives:
A naive approach would be to use Babel traversal to detect something that looks like Object.detectProperty(exports, ...), and use that to parse the value of media.
A more thorough approach would be to actually try to get the full value of the exports variable at the end of the file, but I'm not sure if we can do this with Babel traversals?
Just don't support CommonJS packages
There may be other packages that use CommonJS that are outside our control. Doesn't seem like a viable option
Ask the user to use a custom resolver (through the resolver option in .compiledcssrc, for example) that returns ESM build of packages, not CommonJS build
Currently the way we get around this problem is to use a custom resolver. ESM build of @atlaskit/primitives works without issues, as long as our custom resolver returns the ESM build not the CommonJS build.
Tested with @atlaskit/primitives v1.17.0 and @compiled/babel-plugin v0.28.2
The text was updated successfully, but these errors were encountered:
Example:
We expect this to work, because
@compiled/babel-plugin
runs a variety of functions specifically for resolving imported variables. However, we actually get aCannot statically evaluate the value of "MemberExpression
error.This is because the function that finds exports in
@atlaskit/primitives/responsive
only looks forexport
statements in the formexport { media } from './media-helper';
or perhapsexport defaultExport from './test'
. This fails with@atlaskit/primitives
because there are noexport
statements to be found in the output, and so@compiled/babel-plugin
cannot resolve the value ofmedia
.We see in the above screenshot that what we expected to be
export { media } from './media-helper'
in TypeScript is in fact this boilerplate code in@atlaskit/primitives
:Some potential ways to fix this issue:
require
andexports
syntax, and add handling for this in the@compiled/babel-plugin
resolver functionsObject.detectProperty(exports, ...)
, and use that to parse the value ofmedia
.exports
variable at the end of the file, but I'm not sure if we can do this with Babel traversals?resolver
option in.compiledcssrc
, for example) that returns ESM build of packages, not CommonJS buildCurrently the way we get around this problem is to use a custom resolver. ESM build of
@atlaskit/primitives
works without issues, as long as our custom resolver returns the ESM build not the CommonJS build.Tested with
@atlaskit/primitives v1.17.0
and@compiled/babel-plugin v0.28.2
The text was updated successfully, but these errors were encountered: