Closed ehamery closed 11 months ago
are you using vite?
@jedisct1 was the issue fixed?
I don't know :)
Someone asked you a question and you never replied, so I guess you don't need this any more?
It's surprising that after almost a year, the first question it was this fixed instead of helping us help you, ANYWAY! For anyone having the same issues and that are using vite, here is the solution that worked for me. The full source code is available here https://gitlab.com/higenku/apps/account/-/tree/dev/client?ref_type=heads
take a closer look into these files:
It is even more surprising that nobody tried to reproduce the issue from the given description; and instead, after 10 months, wild guess is made to blame a third party module, ANYWAY!
I do not use vitejs if that was what @lmtr0 was referring to.
I mean..... I'm not having that issue using vite with SvelteKit, as I described on the website that I was building using libsodium for encryption. Without a proper response to as which package bundler you are using (if using one at all) it's difficult to reproduce the issue. It's like trying to find hair in an egg without knowing what an egg is. You cannot expect developers to just go out of their way and test hundreds of javascript frameworks, package bundlers and UI libraries on hundreds of runtimes to try and find an error that YOU are having, IT IS A HUGE WASTE OF TIME. It's easier if you help us narrow down the problem, so we can be efficient
Moving on, are you using a package bundler at all? Are you using a static site generator, a framework or typescript? What are you trying to accomplish? a website, mobile app, desktop app with electron? Can you please describe your environment?
@jedisct1 can you please reopen the issue?
thx @jedisct1
I am not sure why @lmtr0 you are insisting on adding extra parameters to the issue... So instead of wasting time in litanies you could just read at the description of the issue. To make it even clearer:
file1.ts
and file2.ts
, in each:
import libsodium from 'libsodium-wrappers';
to the topawait libsodium.ready
and another function from libsodium
main.ts
, in it:
file1
and file2
file1
and file2
node main.js
No extra package, framework or whatever is needed.
file1.ts
:import libsodium from 'libsodium-wrappers';
export async function test() {
await libsodium.ready;
console.log('libsodium is ready');
}
file2.ts
:import libsodium from 'libsodium-wrappers';
export async function test2() {
await libsodium.ready;
console.log('libsodium is ready (2)');
}
main.ts
:import {test} from './file1';
import {test2} from './file2';
test();
test2();
package.json
:{ "dependencies": { "libsodium-wrappers": "^0.7.13" } }
Running:
$ bun main.ts
libsodium is ready
libsodium is ready (2)
No issues here.
That being said, initializing it twice is not expected. You should only initialize it once once your application starts, and then use that instance everywhere afterwards.
If it's not an actual application with a start function, just do something like:
let _sodium: any;
export async function sodiumInstance() {
if (!_sodium) {
_sodium = await libsodium.ready;
}
return _sodium;
}
at this point we can assume that this is not an issue anymore, great, lets move on! Unfortunately I cannot close this issue
thank you and sorry for the extra work
Hi, I am trying to use
libsodium-wrappers
in Typescript with:I am doing this in several files where I use
libsodium
. But then if I import more than 1 of those files in the same file, any call toawait libsodium.ready
throws an exception:The object that is not defined is
I.asm
Any idea what may cause that? And how I can fix it? Any help would be much appreciated.