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

Referencing a crate in the parent directory as ../ fails #22

Open
chinoto opened this issue Mar 10, 2023 · 2 comments
Open

Referencing a crate in the parent directory as ../ fails #22

chinoto opened this issue Mar 10, 2023 · 2 comments

Comments

@chinoto
Copy link

chinoto commented Mar 10, 2023

The error given is

error when starting dev server:
Error: ENOENT: no such file or directory, open '~/mre_vite_outside/my-crate/www/...js'
    at Object.openSync (node:fs:590:3)
    at Object.readFileSync (node:fs:458:35)
    at prepareBuild (~/mre_vite_outside/my-crate/www/node_modules/vite-plugin-wasm-pack/dist/index.js:125:47)
    at async Context.buildStart (~/mre_vite_outside/my-crate/www/node_modules/vite-plugin-wasm-pack/dist/index.js:132:17)
    at async Promise.all (index 2)
    at async Object.buildStart (~/mre_vite_outside/my-crate/www/node_modules/vite/dist/node/chunks/dep-689425f3.js:39230:13)
    at async Server.httpServer.listen (~/mre_vite_outside/my-crate/www/node_modules/vite/dist/node/chunks/dep-689425f3.js:60350:21)

and the contents of my-crate/pkg are copied to to my-crate/www, which results in package.json being overridden.

I've found two workarounds to this; the first is to go up another directory and then name the directory that you came from, which may not work if the crate is also the root of the repo and the repo folder was named differently than expected; the second workaround is to use node's path.resolve method to get an absolute path to ../.
My guess as to why this is a problem is because you're expecting the name of the crate in the last segment of the path?

I've made a minimal reproducible example here: https://github.com/chinoto/mre_vite-plugin-wasm-pack_outside/tree/Fail
My workarounds are the last two commits of the master branch: https://github.com/chinoto/mre_vite-plugin-wasm-pack_outside/commits/master

@auberryberry
Copy link

+1 of appreciation, just hit the same issue.

@dukejones
Copy link

Yeah. I went down a rabbit hole upon finding this issue. Really it can be fixed by using path.resolve() in the plugin, to get the whole directory structure, because it pulls the crate name off of the last bit of the directory pointed to. Quick fix is ../../my_crate.

But I saw a whole bunch of stuff I wanted to do differently and forked off. We'll see if it ends up merged back into this repo or if I publish with a different name; but check it out. https://github.com/Identikey/vite-plugin-wasm-pack

It runs the wasm-pack command for you and then loads it directly.

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

No branches or pull requests

3 participants