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?
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.
Sorry I started a new job, have been preoccupied. Glad it's closed 😁
On Tue, 21 Jan 2020, 7:04 pm Alex Crichton, notifications@github.com
wrote:
Closed #1921 https://github.com/rustwasm/wasm-bindgen/issues/1921 via
1969 https://github.com/rustwasm/wasm-bindgen/pull/1969.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/rustwasm/wasm-bindgen/issues/1921?email_source=notifications&email_token=AB7XUGJCRSV7V3WQ6ZMT6LDQ65BMVA5CNFSM4J5QLLS2YY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOWDPQOJY#event-2967406375,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AB7XUGLEYCIX3NTH6IWNCNDQ65BMVANCNFSM4J5QLLSQ
.
Most helpful comment
@alexcrichton its this code at
crates/cli-support/src/js/mod.rs:2776My 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.