esbuild
esbuild copied to clipboard
Invalid define value
error: Invalid define value (must be an entity name or valid JSON syntax): 'wss://'+document.domain+'/wss'
when I use string value define ,The program will not report errors.
but I use the expression define,The program may encounter exceptions.
so, I want to use the expression define,what should I do?
The define option can only replace JSON literals and a few a.b like variables. However, you can use the inject option to provide variables in a more expressive way. For example:
// create a file named shims.js
export const __WS_URL__ = 'wss://'+document.domain+'/wss'
// then inject it
esbuild.build({
...options,
inject: ['./shims.js']
})
I'm closing this issue because esbuild is working as intended here. I agree that inject is likely the best fit for your use case. The difference is that define inlines compile-time constants while inject references (but does not inline) variables from arbitrary code. They are used for different purposes.
I got it.Thanks for your answer @evanw @hyrious