Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[...] /path/to/project/root/package.json can currently [..] have [...] no other fields #1921

Closed
pablosichert opened this issue Dec 19, 2019 · 7 comments · Fixed by #1969
Closed
Labels

Comments

@pablosichert
Copy link
Contributor

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?

@adam-cyclones
Copy link

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>;
}

@pratyushj
Copy link

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

@adam-cyclones
Copy link

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.

@alexcrichton
Copy link
Contributor

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!

@adam-cyclones
Copy link

@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.

@alexcrichton
Copy link
Contributor

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

Tarnadas added a commit to Tarnadas/wasm-bindgen that referenced this issue Jan 21, 2020
Tarnadas added a commit to Tarnadas/wasm-bindgen that referenced this issue Jan 21, 2020
@adam-cyclones
Copy link

adam-cyclones commented Jan 21, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants