Skip to content

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

Description

@chinoto

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions