sha256 window is not defined
peterpeterparker opened this issue · 1 comments
Issue
Referencing nns
package directly from a SvelteKit app leads to an issue with the local dev server if ssr
is true
window is not defined
ReferenceError: window is not defined
at ../../../../node_modules/js-sha256/src/sha256.js:1:572
at ../../../../node_modules/js-sha256/src/sha256.js:1:10537
at /@fs/Users/daviddalbusco/projects/dfinity/ic-js/packages/nns/dist/esm/chunk-Q3ETFEQV.js:1:304
at ../../../../node_modules/js-sha256/src/sha256.js:1:38057
at async instantiateModule
Reproduction
git clone https://github.com/dfinity/ic-js
cd ic-js
npm ci
npm run build --workspaces
cd ../
git clone https://github.com/dfinity/nns-dapp
cd nns-dapp/frontend
npm ci
npm rm @dfinity/nns
npm i ../../ic-js/packages/nns
npm run dev
open browser
Workaround
Disable ssr
for local development in the SvelteKit app.
For the same reason as I closed #315, turns out we always gonna need a lirbary anyway because sha224 is not part of the web specification. Therefore, since we always gonna need one, we can also use the sh256 from same lib and migrating to the platform would only have a minimal impact.