[plugin:linaria] [path-to]\filename: An unexpected runtime error occurred during dependencies evaluation:
[path-to]\node_modules\@babel\core\lib\parser\index.js:75
throw err;
^
SyntaxError: [path-to]\filename: Missing semicolon. (8:1)
Hold up though, because your semicolon might not be missing. Here's the code where that error was occurring, in a file called constants.ts:
export const MOBILE_WIDTH = 414;
export const DESKTOP_WIDTH = 962;
export const RED = 'F00';
export const YELLOW = 'FC0';
export const GREEN = '0F3';
const colors = [RED, YELLOW, GREEN] as const;
export type Colors = typeof colors[number];
The semicolon was allegedly missing from the end of [RED, YELLOW, GREEN]. But that line of code is fine, and interestingly the error message disappeared when the following code - in a completely unrelated file - changed from this:
import { DESKTOP_WIDTH } from '../../constants';
const Container = styled.div`
height: auto;
@media only screen and (min-width: ${DESKTOP_WIDTH}px) {
height: 69px;
}
`;
to this:
const Container = styled.div`
height: auto;
@media only screen and (min-width: 962px) {
height: 69px;
}
`;
The Linaria docs state that [y]ou can interpolate ... imported variables. But if so why does the alleged missing semicolon error occur?
I do not know. But I do know how I fixed it and therefore what might be going on. Following some experimentation I split constants.ts into three files:
constants.ts
export const RED = 'F00';
export const YELLOW = 'FC0';
export const GREEN = '0F3';
types.ts
import { RED, YELLOW, GREEN } from './constant'
const colors = [RED, YELLOW, GREEN] as const;
export type Colors = typeof colors[number];
metrics.ts
export const MOBILE_WIDTH = 414;
export const DESKTOP_WIDTH = 962;
And then tried this again:
import { DESKTOP_WIDTH } from '../../metrics';
const Container = styled.div`
height: auto;
@media only screen and (min-width: ${DESKTOP_WIDTH}px) {
height: 69px;
}
`;
The error message disappeared.
Linaria is a static css library. I expected it to be somewhat dynamic during dev and statically compile at build time. To some degree it is, but it was not quite as flexible as I hoped or assumed it was. Perhaps then, some styles are statically generated at build time and having other values in the same file that are accessed at run time causes something to fall over inside Linaria's core code? I do not know, but more importantly this 'fixes' the 'error'.
And whilst you are here, you may wish to take note that other Linaria error messages can be misleading too.