Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sveltekit example does not work with vercel #2078

Open
1 task done
Elliott-Green opened this issue Mar 7, 2024 · 3 comments
Open
1 task done

Sveltekit example does not work with vercel #2078

Elliott-Green opened this issue Mar 7, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@Elliott-Green
Copy link

Current Behavior

Deploying the sveltekit example repo here https://github.com/blocknative/web3-onboard/tree/main/examples/with-sveltekit
to vercel causes an error

Expected Behavior

Deploying to vercel should return no error.

Steps To Reproduce

https://github.com/Elliott-Green/sk-web3-vercel-minrepo OR https://github.com/blocknative/web3-onboard/tree/main/examples/with-sveltekit

git clone https://github.com/Elliott-Green/sk-web3-vercel-minrepo.git
npm i
npm run build
npm run preview
git commit -m "[chore] poke build"
vercel builds, errors with log

What package is effected by this issue?

@web3-onboard/core

Is this a build or a runtime issue?

Build

Package Version

2.21.0

Node Version

20.10.0

What browsers are you seeing the problem on?

Firefox

Relevant log output

Cloning github.com/Elliott-Green/sk-web3-vercel-minrepo (Branch: main, Commit: d984944)
Cloning completed: 292.694ms
Previous build cache not available
Running "vercel build"
Vercel CLI 33.5.3
Installing dependencies...
yarn install v1.22.17
warning package.json: No license field
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
warning with-sveltekit@0.0.1: No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning "@web3-onboard/walletconnect > @walletconnect/modal > @web3modal/core > valtio > use-sync-external-store@1.2.0" has unmet peer dependency "react@^16.8.0 || ^17.0.0 || ^18.0.0".
warning " > rollup-plugin-polyfill-node@0.12.0" has unmet peer dependency "rollup@^1.20.0 || ^2.0.0 || ^3.0.0".
[4/4] Building fresh packages...
success Saved lockfile.
Done in 21.44s.
Running "yarn run build"
yarn run v1.22.17
warning package.json: No license field
$ vite build
vite v4.0.5 building for production...
transforming...
✓ 677 modules transformed.
6:45:33 PM [vite-plugin-svelte] dom compile done.
package        files  time    avg
with-sveltekit     4 0.17s 43.4ms
[vite]: Rollup failed to resolve import "Buffer" from "/vercel/path0/node_modules/@walletconnect/encoding/dist/esm/index.js".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
error during build:
Error: [vite]: Rollup failed to resolve import "Buffer" from "/vercel/path0/node_modules/@walletconnect/encoding/dist/esm/index.js".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
    at onRollupWarning (file:///vercel/path0/node_modules/vite/dist/node/chunks/dep-9cd3c8cb.js:44636:19)
    at onwarn (file:///vercel/path0/node_modules/vite/dist/node/chunks/dep-9cd3c8cb.js:44407:13)
    at file:///vercel/path0/node_modules/rollup/dist/es/shared/node-entry.js:24276:13
    at Object.logger [as onLog] (file:///vercel/path0/node_modules/rollup/dist/es/shared/node-entry.js:25950:9)
    at ModuleLoader.handleInvalidResolvedId (file:///vercel/path0/node_modules/rollup/dist/es/shared/node-entry.js:24862:26)
    at file:///vercel/path0/node_modules/rollup/dist/es/shared/node-entry.js:24822:26
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Command "yarn run build" exited with 1

Anything else?

No response

Sanity Check

  • If this is a build issue, I have included my build config. If this is a runtime issue, I have included reproduction steps and/or a Minimal, Reproducible Example.
@Elliott-Green Elliott-Green added the bug Something isn't working label Mar 7, 2024
@Adamj1232
Copy link
Member

@Elliott-Green I was able to get it up and running with the following steps:
First, ensure you have @rollup/plugin-commonjs installed:

npm install @rollup/plugin-commonjs --save-dev

Then, include it in your Vite configuration:

import commonjs from '@rollup/plugin-commonjs';

// Inside your Vite config
const config: UserConfig = {
  plugins: [
    sveltekit(),
    commonjs({
      include: /node_modules/ // Only transpile CommonJS modules from node_modules
    }),
    // Your other plugins...
  ],
  // Your other config options...
};

Can you give that a try and let me know?

@Adamj1232
Copy link
Member

PR to get the example working : #2086

@Elliott-Green
Copy link
Author

Elliott-Green commented Mar 15, 2024

Hey @Adamj1232,

Thanks for looking into this.

I've picked the changes up from #2086 but alas, I'm still having the same issues.

Did you ever get a vercel deployment out for 2086? build+preview work locally, so looks ok, but will error on vercel.

Had a few other local issues that I managed to resolve, would recommend these packages get updated as they've been patched to work nicely with commonJS - or something, I have no idea, this side of js is a black box to me.

4:05:42 PM [vite] Error when evaluating SSR module /node_modules/@web3-onboard/core/node_modules/svelte-i18n/dist/runtime.esm.js: failed to import "intl-messageformat"
|- SyntaxError: [vite] Named export 'IntlMessageFormat' not found. The requested module 'intl-messageformat' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'intl-messageformat';
const {IntlMessageFormat} = pkg;

By overriding some of the package versions, I am able to resolve some of my build issues like:

"overrides": {
		"@web3-onboard/core": {
			"svelte-i18n": "^4.0.0",
			"intl-messageformat": "^10.5.1",
			"bnc-sdk": {
				"rxjs": "^7.8.1"
			}
		},
		"@web3-onboard/coinbase": {
			"@coinbase/wallet-sdk": {
				"rxjs": "^7.8.1"
			}
		},
		// Not sure about this one, trying to fix atm
		"@web3-onboard/trezor": {
			"@ethereumjs/tx": "^5.2.1",
			"eth-crypto": {
				"@ethereumjs/tx": "^5.2.1"
			}
		}
	}

Svelte-i18n/intl-messageformat

https://stackoverflow.com/questions/77193468/syntaxerror-when-building-sveltekit-the-requested-module-intl-messageformat-i
kaisermann/svelte-i18n#232

ethereumjs/tx

error during build:
RollupError: [vite-plugin-sveltekit-compile] node_modules/eth-crypto/dist/es/sign-transaction.js (1:9): "Transaction" is not exported by "node_modules/eth-crypto/node_modules/@ethereumjs/tx/dist.browser/index.js", imported by "node_modules/eth-crypto/dist/es/sign-transaction.js".
file: /Users/elliott/Documents/GitHub/5725Cafe/node_modules/eth-crypto/dist/es/sign-transaction.js:1:9
1: import { Transaction } from '@ethereumjs/tx';
            ^
2: import { publicKeyByPrivateKey } from './public-key-by-private-key';
3: import { toAddress as addressByPublicKey } from './public-key';
file: /Users/elliott/Documents/GitHub/5725Cafe/node_modules/eth-crypto/dist/es/sign-transaction.js:1:9
1: import { Transaction } from '@ethereumjs/tx';
            ^
2: import { publicKeyByPrivateKey } from './public-key-by-private-key';
3: import { toAddress as addressByPublicKey } from './public-key';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants