New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow using imported variables in entrypoint options #336
Comments
I have to use literal value instead. |
Yes, you must use literal values when defining options for entrypoints. Why? When importing your entrypoints to get it's options during the build process, the file is imported in a node environment. It doesn't have access to So to get around this, wxt strips all imports from your file, and then imports it. This makes sure any imported modules with side-effects doesn't cause a build failure when accessing one of these global variables. The only solution to solve this problem is to setup a full browser environment while loading the entrypoints files, which I decided would be too error prone initially. So the initial implementation removed imports. I want to allow imported variables to be used for the entrypoint definition, but haven't had the time to enable that yet. Would be open to contributions for this. |
It is inconvient to arrange matches with logic, and is it significant impact of build entrypoints if setup a full browser environment? |
Sorry, I don't understand the question. |
For future reference, here is the file responsible for importing the entrypoints during the build process to grab their options. |
Variable |
Since WXT doesn't run the It's the same reason why this code runs without throwing an error. The example function is never called. function example() {
console.log(someVariableThatDoesNotExist);
}
console.log("Hello world");
Yes. That's why I'd accept a PR to fix this. Eventually, I'll get to this, but not until after v1.0 is out. |
I'm gonna close this issue, it will be fixed in #506, follow that one for updates. |
Describe the bug
In a content script entrypoint, if you import a variable, lets call it
MATCHES
, and try to use that variable to for thematches
option, the build fails with the following error message:But
import { sayHello } from "@/helpers/dev"
is okey.To Reproduce
https://github.com/yunsii/wxt-reproduction
Steps to reproduce the bug using the reproduction:
pnpm i --ignore-scripts
pnpm build --debug
Here's the output:
Expected behavior
Variable
matches
works withdefineContentScript
intuitivelyEnvironment
The text was updated successfully, but these errors were encountered: