question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Svelte App build error

See original GitHub issue

Building Svelte App with rollup fails, even with example (https://codesandbox.io/s/jekzo)

First error :

$ npm run build 
...
[!] Error: Unexpected token (Note that you need @rollup/plugin-json to import JSON files)
node_modules/.pnpm/@ensdomains+ens@0.4.3/node_modules/@ensdomains/ens/build/contracts/ENS.json (2:16)
1: {
2:   "contractName": "ENS",
                   ^
3:   "abi": [
4:     {
Error: Unexpected token (Note that you need @rollup/plugin-json to import JSON files)

After adding @rollup/plugin-json , new error :

[!] Error: 'toBuffer' is not exported by node_modules/.pnpm/ethereumjs-util@7.1.0/node_modules/ethereumjs-util/dist/index.js, imported by node_modules/.pnpm/bnc-onboard@1.31.0/node_modules/bnc-onboard/dist/esm/index-9156d65a.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
node_modules/.pnpm/bnc-onboard@1.31.0/node_modules/bnc-onboard/dist/esm/index-9156d65a.js (35:9)
33: import 'bowser';
34: import '@ensdomains/ensjs';
35: import { toBuffer } from 'ethereumjs-util';
             ^
36: var HANDLE_PIN_PRESS = 'handlePinPress';
37: var BUTTON_COLOR = "#EBEBED";

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
aaronbarnardsoundcommented, Oct 14, 2021

Hey all,

Apologies for all the issues trying to get Onboard working nicely with Svelte. We use Svelte internally at Blocknative for all of our frontends, so we’d love to improve the developer experience here.

The main issue is that bundlers like Rollup, Vite and Snowpack (which are all commonly used with Svelte) don’t have good support for bundling in the node builtins, especially the crypto module. A lot of the wallets we support need these builtins to work correctly and that is what is causing a lot of the errors.

We are actively working on a V2 of Onboard which (among other features) will separate all of the wallets in to it’s own mono repo with all of the packages so that we can isolate these dependency problems from the main library. We are also going to go through and reduce and hopefully remove the node builtin dependencies if possible or bundle the necessary deps in with the wallet modules.

In the meantime I have a working template repo for Svelte that you can check out. It uses Webpack 4 as the bundler. It seems to be a lot more difficult to bundle the node builtins in Webpack 5 so I couldn’t get that working at the moment.

0reactions
jakubdonovancommented, Apr 15, 2022

@jakubdonovan Specifically here is important

Okay, so I installed web3-onboard and pasted the sveltekit config. The modal works, but I ran into a number of issues. Some were fixed in last night’s update, but two app breaking issues remained.

Here is a repository I made just for this https://github.com/jakubdonovan/web3-onboard-svelte

1: The app fails to build with npm run build

onboard-test on  master [!] via  v17.2.0 took 3m36s ❯ npm run build blank-supabase@0.0.1 build svelte-kit build

vite v2.9.1 building for production… ✓ 902 modules transformed. .svelte-kit/output/client/_app/manifest.json 11.37 KiB .svelte-kit/output/client/_app/pages/__layout.svelte-262df0f1.js 0.53 KiB / gzip: 0.35 KiB .svelte-kit/output/client/_app/error.svelte-dbbbbc49.js 1.56 KiB / gzip: 0.74 KiB .svelte-kit/output/client/_app/pages/index.svelte-1482e438.js 0.14 KiB / gzip: 0.11 KiB .svelte-kit/output/client/_app/chunks/index-4e97ed67.js 0.79 KiB / gzip: 0.48 KiB .svelte-kit/output/client/_app/chunks/index-a11dff51.js 7.11 KiB / gzip: 2.89 KiB .svelte-kit/output/client/_app/start-42770ad0.js 22.39 KiB / gzip: 8.44 KiB .svelte-kit/output/client/_app/chunks/mobile-36eff9c3.js 7.82 KiB / gzip: 3.10 KiB .svelte-kit/output/client/_app/chunks/icon-ab2a4f6d.js 1.57 KiB / gzip: 0.70 KiB .svelte-kit/output/client/_app/chunks/index-c6d1826a.js 13.27 KiB / gzip: 4.58 KiB .svelte-kit/output/client/_app/chunks/index-e1bee543.js 3.00 KiB / gzip: 1.35 KiB .svelte-kit/output/client/_app/chunks/metamask-db57a758.js 3.85 KiB / gzip: 1.09 KiB .svelte-kit/output/client/_app/chunks/brave-eb140ee4.js 7.18 KiB / gzip: 2.60 KiB .svelte-kit/output/client/_app/chunks/coinbase-ee07f467.js 0.77 KiB / gzip: 0.37 KiB .svelte-kit/output/client/_app/chunks/trust-ae639413.js 2.52 KiB / gzip: 1.09 KiB .svelte-kit/output/client/_app/chunks/detected-29b2fdc8.js 0.45 KiB / gzip: 0.29 KiB .svelte-kit/output/client/_app/chunks/opera-b9006edb.js 1.87 KiB / gzip: 0.81 KiB .svelte-kit/output/client/_app/chunks/alphawallet-5a234a03.js 5.18 KiB / gzip: 2.39 KiB .svelte-kit/output/client/_app/chunks/status-940845c8.js 0.54 KiB / gzip: 0.32 KiB .svelte-kit/output/client/_app/chunks/atoken-c3378c96.js 1.68 KiB / gzip: 0.80 KiB .svelte-kit/output/client/_app/chunks/zipWith-36b06beb.js 26.45 KiB / gzip: 7.98 KiB .svelte-kit/output/client/_app/chunks/blockwallet-d7636c27.js 0.36 KiB / gzip: 0.25 KiB .svelte-kit/output/client/_app/chunks/dcent-2a2e6b38.js 1.12 KiB / gzip: 0.62 KiB .svelte-kit/output/client/_app/chunks/hyperpay-fde99ff2.js 0.66 KiB / gzip: 0.37 KiB .svelte-kit/output/client/_app/chunks/bitpie-0fdb9a6b.js 3.20 KiB / gzip: 1.32 KiB .svelte-kit/output/client/_app/chunks/huobiwallet-4ff47423.js 1.33 KiB / gzip: 0.66 KiB .svelte-kit/output/client/_app/chunks/imtoken-2e24ca2c.js 1.53 KiB / gzip: 0.84 KiB .svelte-kit/output/client/_app/chunks/frame-c63065cd.js 0.68 KiB / gzip: 0.37 KiB .svelte-kit/output/client/_app/chunks/ownbit-d484ea79.js 1.71 KiB / gzip: 0.96 KiB .svelte-kit/output/client/_app/chunks/tokenpocket-8f737f3e.js 0.94 KiB / gzip: 0.52 KiB .svelte-kit/output/client/_app/chunks/meetone-38b74bcd.js 2.87 KiB / gzip: 2.07 KiB .svelte-kit/output/client/_app/chunks/liquality-10e9b17a.js 1.40 KiB / gzip: 0.74 KiB .svelte-kit/output/client/_app/chunks/xdefi-532667f6.js 2.12 KiB / gzip: 1.17 KiB .svelte-kit/output/client/_app/chunks/mykey-d40bc952.js 19.40 KiB / gzip: 14.61 KiB .svelte-kit/output/client/_app/assets/index-190c917e.css 1.46 KiB / gzip: 0.46 KiB .svelte-kit/output/client/_app/chunks/tokenary-999a59a2.js 0.72 KiB / gzip: 0.45 KiB .svelte-kit/output/client/_app/chunks/oneInch-259936b5.js 6.64 KiB / gzip: 2.87 KiB .svelte-kit/output/client/_app/chunks/tp-0e31d205.js 18.33 KiB / gzip: 13.88 KiB .svelte-kit/output/client/_app/assets/pages/__layout.svelte-61d80ba0.css 4.25 KiB / gzip: 1.69 KiB .svelte-kit/output/client/_app/chunks/tallywallet-7c084638.js 9.82 KiB / gzip: 4.48 KiB .svelte-kit/output/client/_app/chunks/binance-623efcc0.js 21.94 KiB / gzip: 16.60 KiB .svelte-kit/output/client/_app/chunks/index-a9c075d2.js 97.28 KiB / gzip: 27.26 KiB .svelte-kit/output/client/_app/chunks/index-d413fcec.js 101.46 KiB / gzip: 33.84 KiB .svelte-kit/output/client/_app/chunks/index-97d6a8e8.js 1022.15 KiB / gzip: 324.46 KiB

(!) Some chunks are larger than 500 KiB after minification. Consider:

  • Using dynamic import() to code-split the application
  • Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/guide/en/#outputmanualchunks
  • Adjust chunk size limit for this warning via build.chunkSizeWarningLimit. vite v2.9.1 building SSR bundle for production… ✓ 1046 modules transformed. Generated an empty chunk: “hooks” .svelte-kit/output/server/manifest.json 1.21 KiB .svelte-kit/output/server/index.js 65.52 KiB .svelte-kit/output/server/entries/pages/__layout.svelte.js 0.25 KiB .svelte-kit/output/server/entries/fallbacks/error.svelte.js 0.72 KiB .svelte-kit/output/server/chunks/index-110612cb.js 2.78 KiB .svelte-kit/output/server/chunks/hooks-1c45ba0b.js 0.00 KiB .svelte-kit/output/server/entries/pages/index.svelte.js 1002.83 KiB TypeError: Cannot read properties of undefined (reading ‘string’) at file:///Users/jakubdonovan/Documents/code/onboard-test/.svelte-kit/output/server/entries/pages/index.svelte.js:16959:24 at ModuleJob.run (node:internal/modules/esm/module_job:195:25) at async Promise.all (index 0) at async ESMLoader.import (node:internal/modules/esm/loader:331:24) at async Promise.all (index 1) at async respond$1 (file:///Users/jakubdonovan/Documents/code/onboard-test/.svelte-kit/output/server/index.js:1480:13) at async resolve (file:///Users/jakubdonovan/Documents/code/onboard-test/.svelte-kit/output/server/index.js:1859:105) at async respond (file:///Users/jakubdonovan/Documents/code/onboard-test/.svelte-kit/output/server/index.js:1815:22) at async visit (file:///Users/jakubdonovan/Documents/code/onboard-test/node_modules/@sveltejs/kit/dist/chunks/index2.js:1094:20)

500 / at file:///Users/jakubdonovan/Documents/code/onboard-test/node_modules/@sveltejs/kit/dist/chunks/index2.js:980:11 at save (file:///Users/jakubdonovan/Documents/code/onboard-test/node_modules/@sveltejs/kit/dist/chunks/index2.js:1213:4) at visit (file:///Users/jakubdonovan/Documents/code/onboard-test/node_modules/@sveltejs/kit/dist/chunks/index2.js:1104:3) at processTicksAndRejections (node:internal/process/task_queues:96:5)

Lastly, adding ledger, trezor, or gnosis all results in the following error

✘ [ERROR] Could not read from file: /Users/jakubdonovan/Documents/code/onboard-test/crypto-browserify

node_modules/eccrypto/browser.js:9:25:
  9 │ var nodeCrypto = require('crypto');
    ╵                          ~~~~~~~~

✘ [ERROR] Could not read from file: /Users/jakubdonovan/Documents/code/onboard-test/stream-browserify

node_modules/cipher-base/index.js:2:24:
  2 │ var Transform = require('stream').Transform
    ╵                         ~~~~~~~~

02:31:49 [vite] error while updating dependencies: Error: Build failed with 2 errors: node_modules/cipher-base/index.js:2:24: ERROR: Could not read from file: /Users/jakubdonovan/Documents/code/onboard-test/stream-browserify node_modules/eccrypto/browser.js:9:25: ERROR: Could not read from file: /Users/jakubdonovan/Documents/code/onboard-test/crypto-browserify at failureErrorWithLog (/Users/jakubdonovan/Documents/code/onboard-test/node_modules/esbuild/lib/main.js:1603:15) at /Users/jakubdonovan/Documents/code/onboard-test/node_modules/esbuild/lib/main.js:1249:28 at runOnEndCallbacks (/Users/jakubdonovan/Documents/code/onboard-test/node_modules/esbuild/lib/main.js:1034:63) at buildResponseToResult (/Users/jakubdonovan/Documents/code/onboard-test/node_modules/esbuild/lib/main.js:1247:7) at /Users/jakubdonovan/Documents/code/onboard-test/node_modules/esbuild/lib/main.js:1356:14 at /Users/jakubdonovan/Documents/code/onboard-test/node_modules/esbuild/lib/main.js:666:9 at handleIncomingPacket (/Users/jakubdonovan/Documents/code/onboard-test/node_modules/esbuild/lib/main.js:763:9) at Socket.readFromStdout (/Users/jakubdonovan/Documents/code/onboard-test/node_modules/esbuild/lib/main.js:632:7) at Socket.emit (node:events:390:28) at addChunk (node:internal/streams/readable:324:12) Vite Error, /node_modules/.vite/deps/svelte.js?v=093c0ec4 optimized info should be defined Vite Error, /node_modules/.vite/deps/svelte_store.js?v=093c0ec4 optimized info should be defined Vite Error, /node_modules/.vite/deps/svelte_internal.js?v=093c0ec4 optimized info should be defined Vite Error, /node_modules/.vite/deps/svelte.js?v=093c0ec4 optimized info should be defined Vite Error, /node_modules/.vite/deps/svelte_internal.js?v=093c0ec4 optimized info should be defined Vite Error, /node_modules/.vite/deps/svelte_internal.js?v=093c0ec4 optimized info should be defined (x2)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I fix this error when trying to deploy my svelte app on ...
I am trying to deploy my svelte app on GitHub Pages and cannot get rid of these errors I get from running 'npm...
Read more >
Errors • Docs • SvelteKit
Errors are an inevitable fact of software development. SvelteKit handles errors differently depending on where they occur, what kind of errors they are, ......
Read more >
Build error starting with version 171 · Issue #2912 · sveltejs/kit
Describe the bug I am getting the following error when building, starting with version 171: > Using @sveltejs/adapter-node ...
Read more >
Build error when trying to deploy SvelteKit app - Support
I'm getting this error when trying to deploy my SvelteKit app. ENOENT: no such file or directory, open 'build/_redirects'.
Read more >
How to build a simple Svelte app - LogRocket Blog
In addition to logging Redux actions and state, LogRocket records console logs, JavaScript errors, stacktraces, network requests/responses with ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found