Skip to content

web target should allow for importing npm modules #2065

Closed
@Pauan

Description

@Pauan

When using the following code with --target web...

#[wasm_bindgen(module = "foo")]
extern "C" {
    fn foo();
}

...it gives the following error:

error: NPM dependencies have been specified in `package.json` but this is only compatible with the `bundler` and `nodejs` targets

This error is confusing, but more importantly we should allow for npm modules with --target web because:

  1. The Rollup plugin uses --target web internally because it cannot use --target bundler. Rollup can handle npm modules perfectly fine, so this should be allowed.

  2. There are plans to have web native modules, such as std::kv-storage (which was ultimately removed, but there will be other native modules in the future).

  3. By using import maps it is possible to load npm modules in the browser.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions