secrets.js
secrets.js copied to clipboard
Module init fails in a typescript project
Hi there, thanks for sharing & maintaining this library!
I try to use the library in a fresh create-react-app project with Typescript enabled. I get the following error:
secrets.js:456 Uncaught Error: Initialization failed.
at Object.init (secrets.js:456)
at secrets.js:828
at Object.<anonymous> (secrets.js:29)
at secrets.js:31
at Object../node_modules/secrets.js-grempe/secrets.js (secrets.js:41)
at __webpack_require__ (bootstrap:790)
at fn (bootstrap:150)
at Module../src/state/index.ts (index.ts:7)
at __webpack_require__ (bootstrap:790)
at fn (bootstrap:150)
at Module../src/App.tsx ( groupOptions: {} namespace object:25)
at __webpack_require__ (bootstrap:790)
at fn (bootstrap:150)
at Module../src/index.tsx (App.tsx:51)
at __webpack_require__ (bootstrap:790)
at fn (bootstrap:150)
at Object.0 (variables.css?6ef5:37)
at __webpack_require__ (bootstrap:790)
at checkDeferredModules (bootstrap:45)
at Array.webpackJsonpCallback [as push] (bootstrap:32)
at main.chunk.js:1
I tried with:
import * as secrets from 'secrets.js-grempe';
import secrets from 'secrets.js-grempe';
const secrets = require('secrets.js-grempe');
and got the same error.
A global script balise works (<script src="/secrets.js"></script>
).
Hey @lsenta, running into the same issue over here.
If you check the install instructions it says "Requires OpenSSL support compiled into Node" which I don't believe is featured natively in browsers.
In secrets.js you can see that the the package uses a different random method for browsers vs Node.
I think webpack is freaking out because it thinks it needs OpenSSL when, in the browser, it can actually use browser-native methods.
Anyway I haven't found a way around this yet. Currently using a script tag from unpkg (<script src='https://unpkg.com/[email protected]/secrets.min.js' type="text/javascript"></script>
)
Any luck on your end?
Bump Same story on Babel
+1
@fabioginzel @Asphiii
don't know if this helps, but I am using this in an Angular 8 project and faced the same problem.
however, changing line #26 to return (root.secrets = factory(window.crypto))
from return (root.secrets = factory())
resolved the problem for me.
@binaek89
Encountered the same with Angular 9 project and used similar solution, AMD definition lacks crypto
dependency
Facing same issue
secrets.js?3e7f:541 Uncaught Error: Initialization failed. at Object.init (secrets.js?3e7f:541) at eval (secrets.js?3e7f:1057) at Object.eval (secrets.js?3e7f:26) at eval (secrets.js?3e7f:28) at eval (secrets.js?3e7f:38) at Object../node_modules/secrets.js-grempe/secrets.js (chunk-vendors.js:18473) at __webpack_require__ (app.js:854) at fn (app.js:151) at eval (store.js?c0d6:9) at Module../src/store.js (app.js:1207)
Looks like this project is abandoned so I forked and published with the browser fix from @binaek89
To install for your browser project, npm i secrets.js-34r7h
then import secrets from 'secrets.js-34r7h'
Thanks for making this @34r7h . You might want to update the NPM page for secrets.js-34r7h to point to the Github repo for 34r7h/secrets.js.
I'm also happy to help with this.
Thanks ademidun. I forked the repo to allow npm installation and real time imports so I'm not the author. Possibly NPM always points to an original source for forked repos. I can't see where to update the github repo on npm. Please advise if you know otherwise how to proceed.
On Mon, Jan 2, 2023 at 6:41 PM ademidun @.***> wrote:
Thanks for making this @34r7h https://github.com/34r7h . You might want to update the NPM page for secrets.js-34r7h https://www.npmjs.com/package/secrets.js-34r7h to point to the Github repo for 34r7h/secrets.js https://github.com/34r7h/secrets.js.
I'm also happy to help with this.
[image: Screen Shot 2023-01-02 at 7 52 55 AM] https://user-images.githubusercontent.com/9806858/210234151-2cedb304-5f71-494b-92f8-0121a9517832.png
— Reply to this email directly, view it on GitHub https://github.com/grempe/secrets.js/issues/20#issuecomment-1368922762, or unsubscribe https://github.com/notifications/unsubscribe-auth/AATSTIELZC7VKUSBKKJK6FTWQLF6DANCNFSM4JC3SEHQ . You are receiving this because you were mentioned.Message ID: @.***>
@34r7h the link to the repository is configured in the package.json file. Currently line 30.
.
.
.
"repository": {
"type": "git",
"url": "https://github.com/grempe/secrets.js.git"
},
.
.
.
Thank you @RobertW123 and @AlexKorn. Package updated.