You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is the expected behavior?
If a wasm file already has a loader, webpack should not try to parse it.
If this is a feature request, what is motivation or use case for changing the behavior?
I do not want to include the wasm file in my bundle. Instead, I want to lazy load it from a url which was possible in previous webpack versions.
Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.
webpack version: 4.1.1
Reacted by Yves M., Gerald Davis, Erik De Rijcke, kjnnklllk, Amit Jha, Varun Ramesh, Bastien Adam, Maximilian Alexander and 流浪大法师
I don't think this issue should have been closed. Imho, there should be an easier way to do this, especially directly in the import query.
For example, people using the Angular CLI, Create-react-app or similar tools should not have to eject to achieve this, especially since it works very well with webpack 3.
Reacted by Denis Davidyuk, Andrew Steinheiser, Josh Hunt, Gerald Davis, Erik De Rijcke, Amit Jha, Simon Reinisch, David Lechner, DeedleFake, Stefan Dragnev and 9 more
@jfizz what's defaultRules? Is it documented anywhere? Why does this work?
I updated a dependency that now loads a wasm at runtime, and thought, when I got the error about needing a loader for wasm, oh that's easy, I'll just set it up with a rule for file-loader and copy it over verbatim. I was confounded when I kept getting errors about "magic header not detected" with a stack trace that clearly showed that Webpack wanted to use a wasm-specific loader even though I told it not to.
Your fix got the build working, but damn it Webpack, every time this kind of mysterious "helpful" behavior kills half a day for me I feel more inclined to just go back to writing my whole build toolchain with shell scripts. WTF?
Reacted by Anton, Junpei Kawamoto, Kaelan Cooter, Caylan, Paul Berg, Max Taldykin, Erik De Rijcke, George Aristy, Pavel, DeedleFake and 9 more
@xtuc It appears to be a text file because it was previously loaded by file-loader, which is the issue. I am suggesting: If a wasm file already has a loader, webpack should not try to parse it.
@thw0rted I discovered it by looking at the source:
For the record, I'm still pissed that Webpack hasn't documented this, but I think you can actually get rid of the error by just adding type: "javascript/auto" to the rule for /\.wasm$/, without touching defaultRules.
Reacted by Junpei Kawamoto, Denis Davidyuk, jasonszhao, Caylan, donotlb, Erik De Rijcke, George Reznik, Pavle Goloskoković, Aled Jones, jahed.dev and 16 more
Reacted by bohendo, hemith, Swen Schäferjohann, Thibault and Julius Liu
No need to be pissed. Webpack is free and provides a ton of functionality. Not every feature is documented, and historically webpack has lacked documentation but they've gotten a ton better. They always welcome PRs
Reacted by Chris Deacy, Andrew Kowalczyk, Yue Yang, Joshua Byrd, Josh Hunt, adjenks, Marcos, ptrkvsky and 流浪大法师
Reacted by architect-z, Ophir LOJKINE and Alla Panchenko
Sorry @olsonpm , you are of course correct -- I hate when people show up to an open-source project and make demands, and I was out of line to sound like the volunteer maintainers aren't doing enough.
What bothers me is when docs are incomplete or out of date, and I don't know enough about the project to fix them myself. If it's something I have a decent grasp of I don't mind reading the source to figure out the rest, but a lot of Webpack has always seemed a bit black-magic to me. Delving into the internals feels kind of daunting, and the source @jfizz linked to is nearly comment-free, which doesn't help.
Reacted by olsonpm, Kaelan Cooter, Paul Berg, Yue Yang, Joshua Byrd, Tim Lander, jahed.dev, adjenks, Ophir LOJKINE, Ross Williams and 2 more
Hello ! Could this be re-opened, since it still seems to be an issue for a lot of people ?
Why does webpack still try to parse the wasm file when instructed to load it with file-loader ?
Is there a solution for those using create-react-app ?
Reacted by logist322, calvbore, Charlie Collard, redfave, Matthew Planchard, ptrkvsky, Haisham, Sam Wainwright, Paul Alexander, Juan Peist and 6 more
Hello ! Could this be re-opened, since it still seems to be an issue for a lot of people ? Why does webpack still try to parse the wasm file when instructed to load it with file-loader ? Is there a solution for those using create-react-app ?
Speaking for CRA, I moved to craco, so you don"t have to eject from CRA. Adding a craco.config.js at root, with the following content
Activity
jfizz commentedon Mar 12, 2018
I was able to resolve the issue by omitting the wasm rule from module.defaultRules. So my config.module.defaultRules looks like
hccampos commentedon Mar 13, 2018
I don't think this issue should have been closed. Imho, there should be an easier way to do this, especially directly in the import query.
For example, people using the Angular CLI, Create-react-app or similar tools should not have to eject to achieve this, especially since it works very well with webpack 3.
xtuc commentedon Mar 13, 2018
Webpack is currently working on an experimental support for WebAssembly:
see https://github.com/webpack/webpack/blob/master/examples/wasm-simple/webpack.config.js#L10-L11.
Also it seems that the binary you're trying to load is a text file. You can try by opening it in https://webassembly.js.org/share.html.
thw0rted commentedon May 21, 2018
@jfizz what's
defaultRules? Is it documented anywhere? Why does this work?I updated a dependency that now loads a
wasmat runtime, and thought, when I got the error about needing a loader forwasm, oh that's easy, I'll just set it up with a rule forfile-loaderand copy it over verbatim. I was confounded when I kept getting errors about "magic header not detected" with a stack trace that clearly showed that Webpack wanted to use a wasm-specific loader even though I told it not to.Your fix got the build working, but damn it Webpack, every time this kind of mysterious "helpful" behavior kills half a day for me I feel more inclined to just go back to writing my whole build toolchain with shell scripts. WTF?
jfizz commentedon May 23, 2018
@xtuc It appears to be a text file because it was previously loaded by file-loader, which is the issue. I am suggesting: If a wasm file already has a loader, webpack should not try to parse it.
@thw0rted I discovered it by looking at the source:
webpack/lib/WebpackOptionsDefaulter.js
Line 52 in 677eaba
thw0rted commentedon May 23, 2018
For the record, I'm still pissed that Webpack hasn't documented this, but I think you can actually get rid of the error by just adding
type: "javascript/auto"to the rule for/\.wasm$/, without touchingdefaultRules.olsonpm commentedon Jun 18, 2018
No need to be pissed. Webpack is free and provides a ton of functionality. Not every feature is documented, and historically webpack has lacked documentation but they've gotten a ton better. They always welcome PRs
thw0rted commentedon Jun 19, 2018
Sorry @olsonpm , you are of course correct -- I hate when people show up to an open-source project and make demands, and I was out of line to sound like the volunteer maintainers aren't doing enough.
What bothers me is when docs are incomplete or out of date, and I don't know enough about the project to fix them myself. If it's something I have a decent grasp of I don't mind reading the source to figure out the rest, but a lot of Webpack has always seemed a bit black-magic to me. Delving into the internals feels kind of daunting, and the source @jfizz linked to is nearly comment-free, which doesn't help.
Handle *.wasm files using file-loader
Handle *.wasm files using file-loader
lovasoa commentedon Jul 5, 2021
Hello ! Could this be re-opened, since it still seems to be an issue for a lot of people ?
Why does webpack still try to parse the wasm file when instructed to load it with file-loader ?
Is there a solution for those using create-react-app ?
dbuchet commentedon Dec 9, 2022
Speaking for CRA, I moved to craco, so you don"t have to eject from CRA. Adding a
craco.config.jsat root, with the following contentSo i can import like this in React