nshen/vite-plugin-wasm-pack

npm-crate-example appears to be broken

mtizim opened this issue · 3 comments

Commands and outputs to reproduce:

$ git clone  https://github.com/nshen/vite-plugin-wasm-pack.git && cd vite-plugin-wasm-pack/npm-crate-example
...
$ node --version && wasm-pack --version
v16.17.0
wasm-pack 0.10.3
$ yarn install && yarn dev
yarn install v1.22.19
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 3.81s.
yarn run v1.22.19
$ vite
▲ [WARNING] Cannot find base config file "@tsconfig/node12/tsconfig.json" [tsconfig.json]

    ../tsconfig.json:2:15:
      2 │     "extends": "@tsconfig/node12/tsconfig.json",
        ╵                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

failed to load config from /home/mtizim/testing/vite-plugin-wasm-pack/npm-crate-example/vite.config.ts
error when starting dev server:
Error: Cannot find module 'test-npm-crate'
Require stack:
- /home/mtizim/testing/vite-plugin-wasm-pack/npm-crate-example/node_modules/vite-plugin-wasm-pack/dist/index.js
- /home/mtizim/testing/vite-plugin-wasm-pack/npm-crate-example/vite.config.ts
- /home/mtizim/testing/vite-plugin-wasm-pack/npm-crate-example/node_modules/vite/dist/node/chunks/dep-689425f3.js
- /home/mtizim/testing/vite-plugin-wasm-pack/npm-crate-example/node_modules/vite/dist/node/cli.js
- /home/mtizim/testing/vite-plugin-wasm-pack/npm-crate-example/node_modules/vite/bin/vite.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at /home/mtizim/testing/vite-plugin-wasm-pack/npm-crate-example/node_modules/vite-plugin-wasm-pack/dist/index.js:58:62
    at Array.forEach (<anonymous>)
    at vitePluginWasmPack (/home/mtizim/testing/vite-plugin-wasm-pack/npm-crate-example/node_modules/vite-plugin-wasm-pack/dist/index.js:56:17)
    at Object.<anonymous> (/home/mtizim/testing/vite-plugin-wasm-pack/npm-crate-example/vite.config.ts:37:54)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.require.extensions.<computed> [as .ts] (/home/mtizim/testing/vite-plugin-wasm-pack/npm-crate-example/node_modules/vite/dist/node/chunks/dep-689425f3.js:62006:20)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)�[39m
Command failed with exit code 1.

I ran into the same problem with finding the module with my own package, so I tried to reproduce the example - and it fails on my machine.

This is a regression in 0.1.12 - the example works after changing to 0.1.11

Currently, wasm-pack does not create main property in pacakge.json
0.1.12 use require.resolve to get path of module path but require.resolve can not find module that does not have main property in there package.json.
I think it can be fixed with it.

const wasmDirectory = path.dirname(require.resolve(path.join(cratePath, 'package.json'));

go back last 0.1.11 is only solution because it does not use require.resolve.

Had a similar issue with my own package, I also just went back to the older version 0.1.11 and now everything works.