[WASM] Module not found: Error: Can't resolve
See original GitHub issueπ bug report
Description
wasm-pack creates a bundle which ends up doing this:
import * as wasm from './my_wasm' (my_wasm is in reality my_wasm.wasm, notice the absence of the .wasm extension.)
When I import the package in my angular project I get the following error during ng build:
Module not found: Error: Can't resolve './my_wasm' in 'my_package'.
While it is supposed to work with Webpack. As far as I can tell one solution is to add resolve.extensions: ['.wasm'] to the webpack configuration, but Angular doesnβt expose that option.
π Your Environment
Angular Version: 8.0.3
Anything else relevant?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Module not found: Error: Can't resolve 'env' Β· Issue #1907
I have this issue as well, but I have no clue from which crate. I have a working Rust lib that I compiled...
Read more >Rust/Wasm: Module not found: Error: Can't resolve 'env' in
In my rust crate (which is a --lib crate), I only call wasm-pack build --target browser . This will create a pkg folder...
Read more >Module not found: Error: Can't resolve 'whatwg-fetch'
I'm trying to merge Cornerstone 4.8.0 into my theme and I get this error when I try to bundle or start stencil. Does...
Read more >How to fix 'Module not found: Can't resolve 'http' in ... - YouTube
Basically, just change 'react-scripts' to 4.0.2 in your package.json and run `npm install` again :D Follow me on Twitter:Β ...
Read more >module not found error can't resolve 'fs' in react js
Your quick fix is to take react scripts down to v4 until a fix for v5 is in place unless you are comfortable...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think youβre giving Webpack a bit too much importance in this topic. Webpack is very popular, but that doesnβt mean everyone uses Webpack.
For instance, a lot of toolchains use Rollup instead. The WASM rollup plugin shows an example of importing a
.wasmfile with the extension. Parcel is popular as well, and their WASM support also lists an example of using the extension. I couldnβt actually find a page in the Webpack docs showing how to use WASM, but there is an example in the repository that also shows imports with the extension. Aside from bundlers, Both browsers and NodeJS show examples of loading WASM files with an extension. So from this admittedly short survey of the package and runtime landscape, I saw none that directed users to import WASM without extensions.If you have a library and you package it in a way that assumes Webpack, then you are limiting how consumers can use your library. The limitations are both that consumers must use webpack, and that webpack must be configured in a certain way to use the library. This is a serious limitation because it gets passed on transitively to both your direct and indirect consumers. A user might not use a library directly and still run into these problems because of an indirect dependency.
The specific case of changing the an extension resolver also has performance implications. Thatβs the list of extensions the resolver will try to load before it gives up on loading a file. So each extension added there increases total file system operations by a factor relative to its position in the priority array. In Webpackβs case,
.wasmis the first one, followed by.mjs, then.js, then.json. If I ask Webpack to bundle a.jsfile without an extension, it will first try to load.wasmand.mjs. So for the case of.jsfiles, this triples file reads for existing files. For nonexistent files, it adds 1/4 more reads. This cost is incurred for all resolutions, so a large project that uses a single library with a.wasmimport must pay the cost on all attempted resolutions.Iβm sure Webpack has great reasons for listing
.wasmon their default extension resolver. But like I said before, it was never a goal for Angular CLI to expose Webpack semantics. Another example of not exposing Webpack semantics is not usingrequirein user code for.htmland.cssfiles, or not exposing Node globals. We avoid Webpack-specific semantics because it creates coupling of the CLI and user code to Webpack. If in the future we want to migrate to another setup, this couple would create problems. If a user wants to move away from the CLI to another bundler, the same coupling will also create problems for them.If importing
.wasmfiles without an extension was indeed a standard in platforms (like NodeJS or Chrome), it would make sense for Angular CLI to do it. If it was common practice among bundlers, it would make sense to consider the pros and cons and perhaps do it as well. But as far as I can tell itβs neither.If you have a library that assumes the
.wasmextension will automatically be attempted by the consumers toolchain, I urge you to adopt a more consumer friendly packaging approach. Coupling your library to the semantics of a specific tool (be it Webpack, or any other) is harmful for the JS ecosystem.This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.