-
Notifications
You must be signed in to change notification settings - Fork 116
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
sodium.randombytes_buf is not a function #882
Comments
This is most likely related to airgap-it/beacon-sdk#138 |
Confirming that this appears to be a beacon-sdk issue as I get the same results with the taquito-less version (beacon-sdk 2.2.9): import { DAppClient } from "@airgap/beacon-sdk";
const dAppClient = new DAppClient({ name: "Beacon Docs" });
sync();
async function sync() {
try {
console.log("Requesting permissions...");
const permissions = await dAppClient.requestPermissions();
console.log("Got permissions:", permissions.address);
} catch (error) {
console.log("Got error:", error);
}
} I wasn't able to get the "@taquito/beacon-wallet": "^6.4.0-ledger.0",
"@taquito/taquito": "^6.4.0-ledger.0", |
Just a remark:
did not fix the problem for me ("@taquito/taquito": "^9.2.0", "@taquito/beacon-wallet": "^9.2.0"). This bug should be a failing test and a showstopper. |
same issue with vitejs / sveltekit here |
same issue in a clojurescript project using shadow-cljs build system. |
Any news ? |
Same with vue2 + vite |
I was able to get it to build correctly using the following
|
@BerkeleyTrue, how did you override |
@souljorje I don't remember that being an issue. Here is a link to the code where I create the client and wallet. (warning: clojure ahead) https://github.com/Trewaters/ACDao/blob/feat-init-app/src/tequito/core.cljs It worked fine. Although, I didn't get further than connecting a wallet. |
Vite solutionSetup
Also works with Steps
import { defineConfig, mergeConfig } from 'vite';
export default ({ command }) => {
const isBuild = command === 'build';
return defineConfig({
build: {
target: 'esnext',
commonjsOptions: {
transformMixedEsModules: true,
},
},
resolve: {
alias: {
// dedupe @airgap/beacon-sdk
// I almost have no idea why it needs `cjs` on dev and `esm` on build, but this is how it works 🤷♂️
'@airgap/beacon-sdk': path.resolve(__dirname, `./node_modules/@airgap/beacon-sdk/dist/${isBuild ? 'esm' : 'cjs'}/index.js`),
// polyfills
'readable-stream': 'vite-compatible-readable-stream',
stream: 'vite-compatible-readable-stream',
},
},
});
}
<html>
<head>
<script>
const global = globalThis;
</script>
<script type="module">
import { Buffer } from 'buffer';
window.Buffer = Buffer;
</script>
</head>
<!-- ... -->
</html> Voila! Why da hell it it needs P.S. I advice to use dynamic imports for Related |
yes, works on dev but throws on build for me as well. > |
@clemsos check update, now it works 100%! |
@souljorje yes it works ! lifesaver, thx |
@souljorje A lifesaver. I'm getting a |
@souljorje Oops, my error, I didn't see your const definition above. Thanks! |
Hi, I had same issue. Solution in #882 (comment) works well, but in case you would like to use stable version of beacon-sdk instead of beta, it can be done as follows:
import { defineConfig, mergeConfig } from 'vite';
export default ({ command }) => {
const isBuild = env.command === 'build';
const devOnlyResolve = isBuild ? {} : {
"@airgap/beacon-dapp": `./src/vendor/walletbeacon.dapp.min.js`,
}
return defineConfig({
// ...
resolve: {
alias: {
...devOnlyResolve,
// polyfills
'readable-stream': 'vite-compatible-readable-stream',
stream: 'vite-compatible-readable-stream',
},
},
// ...
});
} This fixed vite dev setup for me. Build works out of box for me so the resolve is applied only to for dev. |
I have a working app with Svelte, Vitejs, Taquito, and the Beacon wallet at this address => https://github.com/claudebarde/taquito-bundlers-testing/tree/main/vitejs |
It looks like I made SvelteKit work!
The dapp builds in dev mode (haven't tested in prod for now) and I was able to send a transaction to a contract on Hangzhounet with this config. |
Yes!! This is the most straight forward way, I can confirm it works in svelte kit! |
@melMass Have you been able to build the app? |
Hi Claude! It does work indeed! import adapter from '@sveltejs/adapter-auto';
import preprocess from 'svelte-preprocess';
import path, { dirname } from 'path'
import { fileURLToPath } from 'url'
const filePath = dirname(fileURLToPath(import.meta.url))
const sassPath = `${filePath}/src/styles/`
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: preprocess({
}),
kit: {
adapter: adapter(),
vite: {
resolve: {
alias: {
"$styles": path.resolve("./src/styles"),
"@airgap/beacon-sdk": path.resolve(
path.resolve(),
`./node_modules/@airgap/beacon-sdk/dist/walletbeacon.min.js`
),
// polyfills
"readable-stream": "vite-compatible-readable-stream",
stream: "vite-compatible-readable-stream"
},
},
optimizeDeps: {
esbuildOptions: {
define: {
global: 'globalThis',
'process': JSON.stringify({
env: {
NODE_DEBUG: '',
}
}),
}
}
}
}
}
};
export default config; |
Right, I added the adapter for Netlify and that's when things went sideways! It looks like it builds properly with the |
Version 3 of the Beacon SDK broke all the workarounds that were found on my side 😬 |
@claudebarde check my older comment. I edited the code to work with version 3. Or at least it works for me 😄 Just copy |
@claudebarde some additions to my last #882 (comment) and it works:
// vite.config.js
import replace from 'rollup-plugin-re';
import { defineConfig, mergeConfig } from 'vite';
export default ({ command }) => {
const isBuild = command === 'build';
return defineConfig({
plugins: [
{
...replace({
include: ['node_modules/@airgap/**'],
replaces: {
/**
* damn curcus with this beacon-sdk...
* qr doesn't work on dev, but at least the whole wallet works
*/
...isBuild
? {
"import * as qrcode from 'qrcode-generator';": "import qrcode from 'qrcode-generator';",
}
: {
'var libsodium_wrappers_1 = require("libsodium-wrappers")': 'var libsodium_wrappers_1 = require("libsodium-wrappers").default',
},
},
}),
enforce: 'pre',
},
],
optimizeDeps: {
include: [
'@airgap/beacon-sdk',
'@taquito/beacon-wallet',
'@taquito/taquito',
]
}
}; related airgap-it/beacon-sdk#345 |
This made wallet work on build, but still can't use it on dev |
I had the same problem in a Remix codebase. Got it working by using import { Buffer } from 'buffer';
if (typeof document !== 'undefined' && !window.Buffer) {
window.Buffer = Buffer;
}
const { DAppClient, NetworkType, PermissionScope } = require('@airgap/beacon-sdk');
const { BeaconWallet } = require('@taquito/beacon-wallet'); By using |
@xat That looks like a good idea, I will try it with other projects I had problems with, thanks! |
@xat In svelte we can't "require" AFAIK 🥲 |
#882 (comment) worked for me. I updated it to beacon-sdk version 3.1.3. I am using VUE 3 and Vite 3.2.37. If anyone has insight into what the beacon devs might look into, please comment here: airgap-it/beacon-sdk#380 |
Just for another reference in the latest Svelte Kit beta (1.0.0-next.429) and @airgap/beacon-sdk 3.1.3, note that the reason my node_modules are two levels up ( import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import path from 'path';
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
export default ({ command }) => {
const isBuild = command === 'build';
const devOnlyResolve = isBuild ? {} : {
"@airgap/beacon-dapp": path.resolve(__dirname, `../../node_modules/@airgap/beacon-dapp/dist/cjs/index.js`),
"@airgap/beacon-sdk": path.resolve(__dirname, `../../node_modules/@airgap/beacon-sdk/dist/cjs/index.js`),
}
return defineConfig({
plugins: [
sveltekit(),
],
server: {
port: 3004,
},
resolve: {
alias: {
...devOnlyResolve,
"readable-stream": "vite-compatible-readable-stream",
stream: "vite-compatible-readable-stream"
}
},
define: {
global: "globalThis"
},
optimizeDeps: {
commonjsOptions: {
transformMixedEsModules: true
},
esbuildOptions: {
// Enable esbuild polyfill plugins
plugins: isBuild ? [] : [
NodeGlobalsPolyfillPlugin({
process: true,
buffer: true
}),
]
}
},
build: {
target: "esnext",
commonjsOptions: {
transformMixedEsModules: true
},
}
});
}
|
it was a beacon issue and then a vite issue, but there is not an issue with Taquito. |
Description
When trying to use the wallet in the frontend with a bundler (tested: parcel, browserify) I can't get the app to work at all. It seems like it's an issue with the way
__importStar
is working in the ES5/CJS build from beacon-sdk module; it does not pull in the entire libsodium object, but a clone of it with less functions.Steps To Reproduce
Paste this in a new
main.js
file:And create an
index.html
file:Now run from terminal:
In console you will get an error:
EDIT: This is fixed with parcel by adding the following in your app's package.json (not sure if browserslist is really needed, but the rest resolves to ES Module imports instead of CJS outputs).
The text was updated successfully, but these errors were encountered: