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

Using with typescript/angular #179

Closed
grosch opened this issue Dec 3, 2018 · 4 comments
Closed

Using with typescript/angular #179

grosch opened this issue Dec 3, 2018 · 4 comments

Comments

@grosch
Copy link

grosch commented Dec 3, 2018

I did an npm install libsodium-wrappers but when I try and build I get this:

WARNING in ./node_modules/libsodium/dist/modules/libsodium.js
Module not found: Error: Can't resolve 'crypto' in '/private/tmp/vtb/node_modules/libsodium/dist/modules'

ERROR in ./node_modules/libsodium/dist/modules/libsodium.js
Module not found: Error: Can't resolve 'path' in '/private/tmp/vtb/node_modules/libsodium/dist/modules'

Are there other npm modules that are required?

@bufke
Copy link

bufke commented Dec 8, 2018

I get the warning too and just ignore it. I don't get the error. How are you building? Angular-cli? Custom webpack? I use libsodium.js with angular-cli. Feel free to look at my configuration.

@grosch
Copy link
Author

grosch commented Dec 23, 2018

OK, I have a bare project that's failing now. I can reproduce it like so.

  1. ng new failing (no routing, plain css)
  2. npm install libsodium-wrappers
  3. Edit src/app/app.component.ts to do an import * as Sodium from 'libsodium-wrappers' and then in the constructor just say const key = Sodium.from_hex('');
  4. npm run build

ng --version says this:

Angular CLI: 7.0.7
Node: 11.5.0
OS: darwin x64
Angular: 7.0.4

@bufke
Copy link

bufke commented Dec 25, 2018

There's two ways to fix this.

You could install the package path npm i path or edit your package.json and add

"browser": {
    "path": false
  }

You can read me here. From what I understand libsodium references path. path is a node thing and doesn't exist in the browser. Libsodium on a browser doesn't actually make use of path but it seems to need it in order to be bundled. Therefore you can set path to be anything or polyfill it. Ah Javascript...

@grosch
Copy link
Author

grosch commented Dec 25, 2018

Thank you, that fixed it!

@grosch grosch closed this as completed Dec 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants