Skip to content

npm run start throws: Error: invalid type: sequence, expected a string at line 5 column 11 #1420

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
haai opened this issue Aug 15, 2024 · 9 comments

Comments

@haai
Copy link

haai commented Aug 15, 2024

πŸ› Bug description

I am try to compile the webpack wasm-pack project and then I get an Rust-Compilation Error:

βœ…  Your crate has been correctly compiled

10% building 0/3 entries 3/3 dependencies 0/3 modulesError: invalid type: sequence, expected a string at line 5 column 11
Caused by: invalid type: sequence, expected a string at line 5 column 11

But there is no good information where this error is coming from.
Do you know a way how to tackle this down?

Guess there is an issue with wasm-bindgen?

πŸ€” Expected Behavior

Compilation successful.
wasm-pack build works fine.

πŸ‘Ÿ Steps to reproduce

unkown .. just run "npm run start".

🌍 Your environment

wasm-pack 0.13.0

@kpreid
Copy link

kpreid commented Dec 30, 2024

I am seeing the same cryptic error, but with different circumstances and timing, and not using npm at all:

$ wasm-pack build --target web --out-dir <path> --dev <path>
[INFO]: 🎯  Checking for the Wasm target...
[INFO]: πŸŒ€  Compiling to Wasm...
    Blocking waiting for file lock on package cache
    Finished `dev` profile [optimized + debuginfo] target(s) in 0.08s
Error: invalid type: sequence, expected a string at line 4 column 19
Caused by: invalid type: sequence, expected a string at line 4 column 19

It occurs randomly, in that if I rerun the same command it will succeed. This isΒ with wasm-pack 0.13.1.

@RossSmyth
Copy link

I am experiencing this too.

@SabrinaJewson
Copy link

SabrinaJewson commented Jan 11, 2025

This appears to be caused by a race condition. I can reproduce it reliably with a command like while wasm-pack build --target web --out-dir pkg; do done running in two terminals.

A quick hack to fix it is wrapping all calls to wasm-pack in a global mutex. For example, if one has wasm-pack installed through Cargo, then one can place this shell script higher up in $PATH:

#!/bin/sh
XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-"/run/user/$UID"}"
exec flock "$XDG_RUNTIME_DIR/wasm-pack-lock" "${CARGO_HOME:-"$HOME/.cargo"}/bin/wasm-pack" "$@"

@RossSmyth
Copy link

I tried this and it works for me!

@SabrinaJewson
Copy link

This is caused by a line in manifest/mod.rs which looks for an existing package.json and decides to deserialize it as a HashMap<String, String>. This line was added in #986 to resolve #606. The actual error is caused because the other instance of wasm-pack also writes out a package.json, which obviously cannot be serialized into a HashMap<String, String> (note that wasm-bindgen does, in fact, output a package.json in the correct format).

Evidently, there are three bugs here:

  1. that HashMap<String, String> is used instead of reading the dependencies field as a HashMap<String, String>;
  2. that this obviously-wrong code path is seemingly never exercised;
  3. that this approach of reading from pkg/package.json to begin with means that parallel execution is always goΓ―ng to be somewhat broken, even if the HashMap<String, String> issue is fixed.

There’s also the more concerning issue of how this obviously-wrong code path ended up in codebase to begin with. Did nobody think to test it once? At any rate, I have the following suggestions:

  1. Decide whether parallel execution of wasm-pack is supported: if so, take steps to ensure external tools like wasm-bindgen write to temporary directories instead of pkg, ensuring that wasm-pack itself only ever writes to pkg, and if not, implement a file-locking scheme to prevent multiple instances of wasm-pack on the same pkg folder from running concurrently;
  2. ascertain why wasm-bindgen is not correctly writing out package.json, and thus why this incorrect code path if left unused.

@ltfschoen
Copy link

A quick hack to fix it is wrapping all calls to wasm-pack in a global mutex. For example, if one has wasm-pack installed through Cargo, then one can place this shell script higher up in $PATH:

#!/bin/sh
XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-"/run/user/$UID"}"
exec flock "$XDG_RUNTIME_DIR/wasm-pack-lock" "${CARGO_HOME:-"$HOME/.cargo"}/bin/wasm-pack" "$@"

i tried to do that in this commit maciejhirsz/kobold@4b18a83 but it still gave the error

@ZabelTech
Copy link

heya!
I needed to get this working so I patched the parsing up: #1483
please have a look if time permits.

MikkelPaulson added a commit to initiative-sh/initiative.sh that referenced this issue Apr 5, 2025
@MikkelPaulson
Copy link

@ZabelTech Thank you for the PR, verified working here! πŸ‘

Unfortunately, since I'm using wasm-pack in a build pipeline, it's not practical to build it on demand. I was able to get a successful build with the even messier hack:

mv package.json package.json.bak
echo -n '{}' > package.json
wasm-pack build --release
mv -f package.json.bak package.json

Obviously this wouldn't work if you're using wasm-pack to publish, but since I'm just building, the contents of package.json don't actually matter.

MikkelPaulson added a commit to initiative-sh/initiative.sh that referenced this issue Apr 6, 2025
MikkelPaulson added a commit to initiative-sh/initiative.sh that referenced this issue Apr 6, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants