Yarn and wasm module linking does not work due to yarn caching

333 Views Asked by At

I have a very simple app here where index.html simply imports index.js where:

index.js

import * as wasm from "wasm";
wasm.greet();

lib.rs

mod utils;
use wasm_bindgen::prelude::*;
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

#[wasm_bindgen]
extern { fn alert(s: &str); }

#[wasm_bindgen]
pub fn greet() { alert("Wasm is running haha!"); }

package.json

...
  "dependencies": {
    "wasm": "portal:../pkg"
  },
...

Now, here is my issue:

  • When I use "file:../pkg" in package.json, everything works, but if I make a change and recompile using wasm-pack it does not update. Even running yarn install will not update. The only way I can get changes to show is by running yarn install --check-files but then the install takes time and it's quite painful.
  • When I use "portal:../pkg" in package.json instead, I get an error ERROR in ./index.js Module not found: Error: Can't resolve "wasm" ..... This is not what I expect.
  • When I use "link:../pkg" everything works as planned, and I do not have to run yarn install every-time I compile to see the changes. This is great and what I really want.

Yet, when I read protocols here https://yarnpkg.com/features/protocols the difference between link and portal is only that portal will follow dependencies if package.json exists in my ../pkg folder. In my case, it does, and I expect to have further dependencies there. So how can I get portal to work? And why is it not working now when link is working?

0

There are 0 best solutions below