Given a file colors.ts that contains an object with color names, importing this object into another file and interpolating colors.blue in a css template will work only on the initial build (esbuild). Making changes to colors.ts and adding a new color (e.g. colors.red) will trigger esbuild to rebuild but when trying to use colors.red in the same css (which rebuilds again) I get an error that the colors.red is not set and I see the following message:
The expression evaluated to 'undefined', which is probably a mistake. If you want it to be inserted into CSS, explicitly cast or transform the value to a string, e.g. - 'String(colors.red)'
Note (1): if I restart esbuild, the error goes away
Environment
Description
Given a file
colors.ts
that contains an object with color names, importing this object into another file and interpolatingcolors.blue
in acss
template will work only on the initial build (esbuild). Making changes tocolors.ts
and adding a new color (e.g.colors.red
) will trigger esbuild to rebuild but when trying to usecolors.red
in the samecss
(which rebuilds again) I get an error that thecolors.red
is not set and I see the following message:Note (1): if I restart esbuild, the error goes away
Note (2): esbuild is set up to watch for changes
Note (3): there are no errors if
colors
andcss
are in the same fileNote (4): I have noticed that disabling
globalCache
with the following config fixes the issueReproducible Demo