Skip to content

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

Open
mohebifar wants to merge 1 commit intodrager:masterfrom
mohebifar:fix/write_package_json_from_wasm_bindgen
Open

fix: Fix the parse error when package.json is generated by wasm-bindgen#1450
mohebifar wants to merge 1 commit intodrager:masterfrom
mohebifar:fix/write_package_json_from_wasm_bindgen

Conversation

@mohebifar
Copy link

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! 📦✅

  • You have the latest version of rustfmt installed
$ rustup component add rustfmt
  • 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 mohebifar marked this pull request as draft November 24, 2024 22:01
Introduces WasmBindgenPackageJson for deserializing package.json generated by wasm-bindgen
@mohebifar mohebifar force-pushed the fix/write_package_json_from_wasm_bindgen branch from bd3caf3 to 4c97177 Compare November 24, 2024 22:05
@mohebifar mohebifar marked this pull request as ready for review November 24, 2024 22:05
@mohebifar
Copy link
Author

Bumping this PR. Any blockers for merging this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant