-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
ReferenceError: __name is not defined #1031
Comments
This comes up in other places too, like #607 |
This doesn't look like output from esbuild. The code generator doesn't generate blank lines like that. So I assume something else is happening after esbuild runs that is messing this up. Another thing to note is that esbuild is not designed to preserve the value of This means you can't just call So if you're using code inside a worker make sure you're not calling |
Do you have an idea what the actual problem is and if it's an issue with Vite? I don't call The output I pasted came out of the sources panel of Firefox DevTools, so that might explain the blank lines. After running var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {value, configurable: true}); This is what I'd expect and maybe Vite removes them for some reason? I'm a little lost here but I guess I'm going to open an issue with Vite. |
I just checked the library I'm using and how it creates the Worker. Turns out this is the code: export function makeWorkerBlob(func: Function, deps: Function[]) {
let str = "'use strict';\n\n" + makeWorkerString(deps);
str += "\n\n\nself.func = " + func.toString() + ";";
str += "\n\n\nself.onmessage = " + onmessage.toString() + ";";
// console.log(str);
return new Blob([str], { type: "application/javascript" });
} To summarize Now I need to figure out, how I can fix this in the library. Thanks anyway @evanw, you pointed me in the right direction. |
I really support @evanw point of view on this. |
I think the most straightforward solution here is that Vite should not have this option force-enabled. I left a comment about this here: vitejs/vite#2376 (comment). |
Thanks for your help with this @evanw! |
So it's probably an issue with Vite? I am encountering this issue using Vite and @react-three/drei's The hook loads a draco decompressor from a static url that I think uses a worker. I have similar code in my browser dev-tools as @sto3psl, and the same I'm not super familiar with the intricacies of web workers. I did set EDIT: I was able to fix it by rolling back Vite v2.0.5. The culprit is v2.1.0+. |
Vite just merged pull request #2742 that fixes this issue, so this can probably be closed. |
Thanks for the update. Closing as this will be fixed in the next Vite release. |
@evanw @sto3psl |
你解决了吗?我和遇到了一样的问题 |
another place where this comes up (currently): microsoft/onnxruntime#18673 |
I'm having this error inside of Never mind, found the issue: privatenumber/tsx#113 |
Hi there, first of all, thanks for all the hard work you put into esbuild, it's awesome!
I have an issue with the
keepNames
option of esbuild. First of all some info about versions. I'm using esbuild through Vite.esbuild
version: 0.9.6What's happening is, that esbuild is bundling a file, where it renames the functions and then adds a
__name
function like so:The problem is, that the
__name
function never gets defined in my module, which is causing the errorReferenceError: __name is not defined
in the browser.The actual input and output files are in this Gist: https://gist.github.com/sto3psl/8bca4562096050559ec51544483edc33
Here are the references with the above mentioned
init
function:esbuild
output: https://gist.github.com/sto3psl/8bca4562096050559ec51544483edc33#file-after-esbuild-js-L35-L58There are a bunch of
__name
references in theesbuild
output but no definition of said function. I'm not sure what's happening but if it helps, this file does run in a Worker. If for some optimization reasons__name
is defined onwindow
or in the main thread in general, it isn't accessible in the Worker.I'd appreciate any help and am not sure if this is a Vite or
esbuild
problem.This is the Vite commit that introduced the
keepNames
behaviour: vitejs/vite@b5cd8c8The text was updated successfully, but these errors were encountered: