wasm-pack icon indicating copy to clipboard operation
wasm-pack copied to clipboard

fix: Fix the parse error when package.json is generated by wasm-bindgen

Open mohebifar opened this issue 1 year ago • 1 comments

When building one of my projects, I kept running into this issue:

wasm-pack build --target web

Error:

Finished `release` profile [optimized] target(s) in 0.05s
Error: invalid type: map, expected a string at line 2 column 18
Caused by: invalid type: map, expected a string at line 2 column 18

Root Cause

The issue originates in the step_create_json and the fn write_package_json. During the build process, the following package.json was generated by wasm-bindgen:

{
  "dependencies": {
    "web-tree-sitter-sg": "0.22.2"
  }
}

While this package.json is valid, the code incorrectly attempted to parse the entire file as a HashMap<String, String>. This led to a failure when merging dependencies because the dependencies field itself is a map, not a string.

Fix

This PR updates the parsing logic to correctly handle the package.json structure.


Make sure these boxes are checked! 📦✅

  • [x] You have the latest version of rustfmt installed
$ rustup component add rustfmt
  • [x] You ran cargo fmt on the code base before submitting
  • [ ] You reference which issue is being closed in the PR text

✨✨ 😄 Thanks so much for contributing to wasm-pack! 😄 ✨✨

mohebifar avatar Nov 24 '24 21:11 mohebifar

Bumping this PR. Any blockers for merging this?

mohebifar avatar Jan 24 '25 04:01 mohebifar