-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Cannot import an ES6 module after JS snippets change #1343
Comments
Relative paths within a @alexcrichton Maybe we should back out the changes until it is feature-complete? |
@BigBigos and @ZacLiveEarth could y'all comment a bit on the uses cases you had which were working before? While it was possible to get @Pauan I unfortunately don't actually know how to implement relative paths given the current set of stable |
@alexcrichton Sure. The module worked with a relative path the first try, I wasn't aware of any issues or complexities surrounding it. Basically, we had an existing React app that we wanted to add Rust to, and we added the rust modules for it in a subdirectory of the main react app. By necessity then to create bindings to functions in the original React app we needed a relative path to escape from the Rust subdirectory. This just works in 0.2.28 |
@ZacLiveEarth but the relative path isn't actually relative to the Rust code, right? Rather it's relative to the final output wasm file? (just confirming) Also can you expand a bit on the build process? Are you using a process like webpack to pull in the wasm module into the main app? Additionally is this JS file referenced here included via anything else or is it only referenced by the wasm file? |
@alexcrichton In my case, I am creating a web app that is based on the wasm module written in Rust. The wasm module (alongside the wasm-bindgen bindings) is output to the Previously I was using I have worked-around this by adding a webpack alias In case it matters, the Rust code is in |
Ok thanks for the info @BigBigos! One thing I forgot to mention earlier is that the change here is a product of RFC 6 for those interested to read over as well. FWIW the breakage here is "somewhat intentional" that we wanted to tighten the restrictions on @BigBigos for importing the wasm file itself that was discussed in RFC 6 so you may be interested in reading up on that! |
For completeness, here's the full code.
It seems that it was relative to the output wasm file (in the pkg directory) by sheer luck. Since we only did this once so far, we never had a chance to figure that out. Our build process uses webpack. I'm not intimately familiar with the details of that and the guy who set it up is out of office. |
I didn't know that, thanks! This will certainly simplify a bit of my code and make the snippet mode work for this use case. The other limitation of imports between JS snippet modules still remains. I will just keep using my work-around described above until it is implemented. Or do you intend to remove support for |
I started reading RFC 6 and am very concerned about the section on depending on additional JS files. Being able to depend on other JS files (and indeed, over a thousand of them not including npm modules) is very important to us. The strategy that seems to be implied by the RFC is that an additional 'copy' of the module and it's imports will be embedded in the wasm. I may be misunderstanding the implications of this, but if it means what I think that's a non-starter. Here's some of the problems that I see with that:
Javascript build processes and their implications are not my strong suit, so please let me know if my concerns are misplaced here. |
@BigBigos oh @ZacLiveEarth oh JS files aren't copied into the wasm module, but rather snippets are all copied to an appropriate location in the output directory so a bundler can work with them. One of the main goals of RFC 6 was to enable crates published to crates.io to be able to write and depend on JS snippets. For the end-user use case (which I think @BigBigos and @ZacLiveEarth y'all both fall into) the RFC isn't really helping much as you already had this working somewhat! The main target was library authors (like I wonder though we can perhaps solve this with a new key like |
@alexcrichton Bit of bike shedding: maybe it should be That could also be useful for importing raw npm modules (like |
Something like that would work for me. I like the @Pauan |
I like @Pauan 's direction for the name better than no_include_snippet as well. I might use the word 'import' instead of 'raw_module' though, since that carries with it all the normal connotations of javascript imports. It does seem like snippets and imports are orthogonal concepts, which may both be important for different use cases. In any case, the pre-existing behavior of 0.2.28 was perfect for our use case, sans confusion about the base path for the relative import. If we rename that functionality to import or raw_module or add a no_snippets flag or whatever, that works for me as well. I think you understand the use case well enough that I'll leave you to the remaining value judgements here as you understand the particular implementation details of wasm-bindgen and wasm-pack better. |
Tiny bit more bikeshedding:
I don't have any particular preference, I think they're all fine. |
I'm personally a fan of |
No objection. |
This allows subverting the checks and resolution performed by the `module` attribute added as part of [RFC 6] and has been discussed in rustwasm#1343. Closes rustwasm#1343 [RFC 6]: rustwasm/rfcs#6
This allows subverting the checks and resolution performed by the `module` attribute added as part of [RFC 6] and has been discussed in rustwasm#1343. Closes rustwasm#1343 [RFC 6]: rustwasm/rfcs#6
Ok! I've pushed up #1353 with these changes. |
The b762948 commit has overloaded the meaning of
#[wasm_bindgen(module = "...")]
. Previously, it has defined an ES6 module import that the JS shim performed and provided to the wasm module. Now it also allows the contents of a JS file to be embedded as a snippet.The new behavior is problematic when the copied module has imports on its own - the relative paths lose their meaning. I would like to still be able to perform an import to the original path without copying the module.
Unanchored paths (i.e. ones that don't start with either
/
,.
or..
) still behave the same as before. However, I need to use a relative path starting with../
, which is explicitly disallowed.The text was updated successfully, but these errors were encountered: