Closed icidasset closed 3 years ago
I was able to reproduce this in a SvelteKit app that also relies on Vite.
Steps:
npm install webnative
src/routes/__layout.svelte
<script>
import * as webnative from "webnative";
import Header from '$lib/Header/index.svelte';
import '../app.css';
</script>
The error is similar, but not exactly the same as above:
This seems similar: https://github.com/vitejs/vite/discussions/2344#discussioncomment-422731
Maybe it can addressed by configuring Vite appropriately.
Another discussion here: https://github.com/vitejs/vite/discussions/2278
More explanation, Vite will not shim node built-ins like process
: https://github.com/vitejs/vite/issues/2723#issuecomment-808690781
Why?
$ yarn why process
yarn why v1.22.10
[1/4] Why do we have the module "process"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "process@0.11.10"
info Reasons this module exists
- "ipfs-core#ipfs-bitswap" depends on it
- Hoisted from "ipfs-core#ipfs-bitswap#process"
info Disk size without dependencies: "36KB"
info Disk size with unique dependencies: "36KB"
info Disk size with transitive dependencies: "36KB"
info Number of shared dependencies: 0
Done in 1.19s.
js-ipfs
Edit: this doesn't seem to be from ipfs-core
and js-ipfs-bitswap
. The above check was run on a branch with ipfs-core
installed, not on main
.
I think process
is not the only thing that's undefined
.
When I "mock" (ie. use vite's define
setting), I get the following error:
Uncaught ReferenceError: global is not defined
at availableTypedArrays (index.js:20)
at node_modules/.pnpm/which-typed-array@1.1.4/node_modules/which-typed-array/index.js (index.js:11)
at __require (chunk-QF434IGH.js?v=90f5c12f:12)
at node_modules/.pnpm/util@0.12.4/node_modules/util/support/types.js (types.js:8)
at __require (chunk-QF434IGH.js?v=90f5c12f:12)
at node_modules/.pnpm/util@0.12.4/node_modules/util/util.js (util.js:467)
at __require (chunk-QF434IGH.js?v=90f5c12f:12)
at node_modules/.pnpm/webnative@0.25.2/node_modules/webnative/dist/index.es5.js (index.ts:243)
at __init (chunk-QF434IGH.js?v=90f5c12f:9)
at dep:webnative:2
I had the same issue here as well ... with vitejs and webnative
Got this while trying to use webnative using https://vitejs.dev/
PS: version 0.24.1 does work