oddsdk / ts-odd

An SDK for building apps with decentralized identity and storage.
https://odd.dev/
Apache License 2.0
179 stars 24 forks source link

process is not defined #237

Closed icidasset closed 3 years ago

icidasset commented 3 years ago
Screenshot 2021-05-23 at 23 37 09 Screenshot 2021-05-23 at 23 37 27

Got this while trying to use webnative using https://vitejs.dev/

import * as webnative from "webnative"

PS: version 0.24.1 does work

bgins commented 3 years ago

I was able to reproduce this in a SvelteKit app that also relies on Vite.

Steps:

  1. Follow the SvelteKit getting started steps
  2. npm install webnative
  3. Import webnative in 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:

err

bgins commented 3 years ago

This seems similar: https://github.com/vitejs/vite/discussions/2344#discussioncomment-422731

Maybe it can addressed by configuring Vite appropriately.

bgins commented 3 years ago

Another discussion here: https://github.com/vitejs/vite/discussions/2278

bgins commented 3 years ago

More explanation, Vite will not shim node built-ins like process: https://github.com/vitejs/vite/issues/2723#issuecomment-808690781

bgins commented 3 years ago

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.

icidasset commented 3 years ago

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
jorishermans commented 3 years ago

I had the same issue here as well ... with vitejs and webnative