Wasm-bindgen: [...] `/path/to/project/root/package.json` can currently [..] have [...] no other fields

Created on 19 Dec 2019  ·  7Comments  ·  Source: rustwasm/wasm-bindgen

Hey there!

I have a project directory, where both cargo and npm reside. The package.json has, among others, a scripts section to centralize custom commands related to the project.

When I add

#[wasm_bindgen(module = "/src/foo.ts")]
[...]

to a Rust file, I get the following error when compiling (in this case by invoking wasm-pack, but it should be unrelated):

error: NPM manifest found at `/path/to/project/root/package.json` can currently only have one key, `dependencies`, and no other fields
Error: Running the wasm-bindgen CLI
Caused by: failed to execute `wasm-bindgen`: exited with exit code: 1

Can you help me understand why this limitation exists? Why is e.g. ignoring the other keys not an option?

question

Most helpful comment

@alexcrichton its this code at crates/cli-support/src/js/mod.rs:2776

if key != "dependencies" || iter.next().is_some() {
            bail!(
                "NPM manifest found at `{}` can currently only have one key, \
                 `dependencies`, and no other fields",
                path.display()
            );
}

My Wasm module is cohabiting with a Typescript package, so I did what most would do, npm init, this means I share this package with several other libraries and test tools. I understand the philosophy of pay for only what you use and minimalism but, the package.json should be out of scope, it is not in Rusts domain. I would trust npm do its validating checks. Unless I am missing something critical I don't understand this check at all, what happens if I just delete it?

Happy to PR this, just not contributed to anything before.

All 7 comments

I am also having the same issue (I am also in a ts project)

I changed my import to point to some JS incase it was that.

#[wasm_bindgen(module = "lib-jess/src/bindings/ts/helpers/import.js")]
extern "C" {
    fn import_jess_sync(path: &str) -> Result<String, JsValue>;
}

I was using JS and had the same error. Had to move all the JS code to a separate folder and it worked :grimacing:

Interesting il try that. I think the function I wanted to export was in the same folder as some ts sources. This looks like an edge case and some unexpected behaviour, certainly unhelpful error either way.

Thanks for the report! This was initially done to be as conservative as possible, but I think that this has tripped up enough users that it's fine to ignore all non-dependencies keys and only use the ones that are relevant. In that sense I'd be happy to have a PR to change this!

@alexcrichton its this code at crates/cli-support/src/js/mod.rs:2776

if key != "dependencies" || iter.next().is_some() {
            bail!(
                "NPM manifest found at `{}` can currently only have one key, \
                 `dependencies`, and no other fields",
                path.display()
            );
}

My Wasm module is cohabiting with a Typescript package, so I did what most would do, npm init, this means I share this package with several other libraries and test tools. I understand the philosophy of pay for only what you use and minimalism but, the package.json should be out of scope, it is not in Rusts domain. I would trust npm do its validating checks. Unless I am missing something critical I don't understand this check at all, what happens if I just delete it?

Happy to PR this, just not contributed to anything before.

@adam-cyclones yep that sounds like the right spot, and it should likely be pretty safe to just delete.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pauldorehill picture pauldorehill  ·  3Comments

hunterlester picture hunterlester  ·  4Comments

pustaczek picture pustaczek  ·  3Comments

fitzgen picture fitzgen  ·  4Comments

MarcAntoine-Arnaud picture MarcAntoine-Arnaud  ·  3Comments