-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
The package "@tensorflow/tfjs-backend-wasm" is not minifier-safe #4253
Comments
I use @tensorflow/tfjs-backend-wasm with webpack and I have no problems. Webpack 4. I can give you my webpack config if you need. |
@annxingyuan i can repro this issue (or at least one that seems related) with the sample webpack project in the repo. For the code mentioned in the issue, it this part of emscripten's output? |
@tafsiri Yes, the code is part of emscripten's output. However we prepend code to it when converting it to a blob. |
@tafsiri Do you think this needs the release blocker tag since it is not specific to master? |
Hmm I was thinking so because the example in the repo doesn't work in current form? What do you think? I think with a closer look we can decide whether we want to this to block the next release (for example if we have to file an upstream bug with emscripten). But thought we should at least investigate before doing another release. |
Work-in-progress PR: emscripten-core/emscripten#12832 |
I'm working on a bug filed by a user of this library against esbuild, a bundler I work on. The
@tensorflow/tfjs-backend-wasm
package breaks when bundled and minified. This problem is not specific to esbuild; it happens with a normal Webpack production build too with all default options. However, this is a problem that needs to be solved in the library itself instead of by the bundler, so I figured I should file an issue here about this.System information
Describe the current behavior
The
@tensorflow/tfjs-backend-wasm
package sometimes breaks when minified. This is the case with Webpack and other bundlers.The specific reason for the breakage is described here: evanw/esbuild#538 (comment). At a high level, this library converts a function to a string and then converts that string back to a function. This essentially "rips" it out of its local scope and injects it into another scope and then re-binds all identifiers. That function accesses a local variable called
_scriptDir
and expects that variable to keep the same name in the function source code.Some ways of fixing this:
This could be fixed by placing the code that should not be minified inside a string instead of using a function expression to contain the code. This will ensure that the minifier will not transform it in any way.
This could be fixed by not using the name of the variable to implement this binding. It would be best to pass the value of this variable as an additional parameter to the function so the function doesn't reach for anything outside of its scope.
There is an alternative hack using direct
eval
if doing this is not possible. This hack is also described in esbuild minify mismanages some border cases evanw/esbuild#538 (comment). Using directeval
is an anti-pattern so I'd only do this if other options don't work.Describe the expected behavior
The
@tensorflow/tfjs-backend-wasm
package should not behave differently when minified.Standalone code to reproduce the issue
There is a full reproduction case here: evanw/esbuild#538 (comment). Note that to hit the issue, you need to have both
WebAssembly SIMD support
andWebAssembly threads support
enabled inchrome://flags/
.The text was updated successfully, but these errors were encountered: