Closed matthewlewisnewton closed 3 years ago
For more context, this is the line I'm blowing up at in the production build (but works in parcel serve
): https://github.com/tensorflow/tfjs/blob/master/tfjs-core/src/environment.ts#L101
Seems this line is pruned: https://github.com/tensorflow/tfjs/blob/1707695aab46f41b75382e908136841a2b1d48ef/tfjs-backend-webgl/src/flags_webgl.ts#L218
This seems to be a known issue on the tfjs side: https://github.com/tensorflow/tfjs/issues/5182 However, the module in question does have the flags file listed as a side effect since that issue was filed - maybe this does not do what I think it does?
"sideEffects": [
"./dist/register_all_kernels.js",
"./dist/flags_webgl.js",
"./dist/base.js",
"./dist/index.js",
"./dist/register_all_kernels.mjs",
"./dist/flags_webgl.mjs",
"./dist/base.mjs",
"./dist/index.mjs",
"./src/register_all_kernels.mjs",
"./src/flags_webgl.mjs",
"./src/base.mjs",
"./src/index.mjs"
]
I would say that the listed sideffects are correct. The problem is that our glob matching of them doesn't check the right thing:
This should be true, but ./
seems to confuse micromatch:
> require("micromatch").isMatch("dist/index.js", "./dist/index.js", {matchBase: true})
false
I found a similar problem here: https://github.com/parcel-bundler/parcel/issues/7218#issuecomment-955571056
I'm using webpack & have the same error on my browser -
Cannot evaluate flag 'CANVAS2D_WILL_READ_FREQUENTLY_FOR_GPU': no evaluation function found.
"dependencies": {
"@tensorflow-models/qna": "^1.0.1",
"@tensorflow/tfjs-backend-cpu": "^3.15.0",
"@tensorflow/tfjs-backend-webgl": "^3.15.0",
"@tensorflow/tfjs-core": "3.15.0",
"@tensorflow/tfjs-converter": "3.15.0",
"http-server": "^14.1.1"
},
"devDependencies": {
"webpack": "^5.87.0",
"webpack-cli": "^5.1.4"
},
"peerDependencies": {
"@types/long": "^4.0.1",
"@types/offscreencanvas": "~2019.3.0",
"@types/seedrandom": "2.4.27",
"@types/webgl-ext": "0.0.30",
"long": "4.0.0",
"node-fetch": "~2.6.1",
"seedrandom": "2.4.3",
"@types/webgl2": "0.0.6"
}
π (maybe) bug report
π Configuration (.babelrc, package.json, cli command)
Package.json:
Entire repo here: https://github.com/matthewlewisnewton/parcel-build-breakage
To see that it builds and tfjs initializes at localhost:1234
npm run localhost
To see it break under build at localhost:8080npm run build && cd dist && python3 -m http.server 8080
π€ Expected Behavior
parcel build --no-optimize
(or ideally,parcel build
with optimizations) should not break code that works under parcel serve.π― Current Behavior
It looks like tfjs-backend-webgl has side effects that it isn't reporting or something, and parcel prunes them. Running the code served from parcel in development mode works as expected, however when running the code from parcel build I run into the follow error on initialization:
π¦ Context
This is probably a misbehaving tfjs module, that repo seems to run all kinds of code on module initialization that could break from being re-written / pruned. But I could not find a way to exclude these files from parcel's rewriting in a way that let them stay working.
π» Code Sample
https://github.com/matthewlewisnewton/parcel-build-breakage
index.html:
index.ts:
π Your Environment