Node-jsonwebtoken: build error while using jsonwebtokens in Angular6

Created on 22 May 2018  路  12Comments  路  Source: auth0/node-jsonwebtoken

ERROR in ./node_modules/jwa/index.js
Module not found: Error: Can't resolve 'crypto' in 'E:\My Code\mycode\pwa\node_modules\jwa'
ERROR in ./node_modules/jws/lib/verify-stream.js
Module not found: Error: Can't resolve 'stream' in 'E:\My Code\mycode\pwa\node_modules\jws\lib'
ERROR in ./node_modules/jws/lib/data-stream.js
Module not found: Error: Can't resolve 'stream' in 'E:\My Code\mycode\pwa\node_modules\jws\lib'
ERROR in ./node_modules/jws/lib/sign-stream.js
Module not found: Error: Can't resolve 'stream' in 'E:\My Code\mycode\pwa\node_modules\jws\lib'

Most helpful comment

I've found a workaround, the error is from the @angular-devkit which is in node_modules.

I've modified the below file
node_modules//src/angular-cli-files/models/webpack-configs/browser.js

at the bottom of the page:
node: false

Change to:
node: { crypto: true, stream: true, buffer: true }

this might be a dirty fix, but really solved the problem.

All 12 comments

Those packages are native in NodeJS. The platform to run this library is NodeJS.

I have seen others running it on browsers, however, I don't know how they made it (webpack? browserify?).

From my understanding Angular generally uses webpack, so this should work. I believe both webpack and browserify use https://github.com/crypto-browserify/crypto-browserify to shim crypto in browser contexts. This should be automatic and not require any further configuration.

@WindIvI it may be worth asking for help on Stackoverflow or the Angular repository, as the issue you are having seems to be outside the scope of this project.

I'm also facing the same issue after upgraded to Angular 6

Had the same issue after migrating to Angular 6 but auth0 also provides a package for angular
https://github.com/auth0/angular2-jwt
You could try this but it only provides a JWT Decoder from what I see

Hello, I have same issue, How to fix it ? (asking this since you close the issue)

I closed it because it is out of the scope of the library. I'd say to try the different options that other users have recommended. As always, if anyone from the community solved it be free to answer with a solution so others with that problem can read it.

Thanks for answer, as @markuszm said, I tried https://github.com/auth0/angular2-jwt and it worked well enought :)

I've found a workaround, the error is from the @angular-devkit which is in node_modules.

I've modified the below file
node_modules//src/angular-cli-files/models/webpack-configs/browser.js

at the bottom of the page:
node: false

Change to:
node: { crypto: true, stream: true, buffer: true }

this might be a dirty fix, but really solved the problem.

Hey, for the path I think you mean:

node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js

I am facing same issue.. Please tell me way....? How Fixed it.

I am able to solve this project by adding
"browser": { "crypto": false, "stream": false }
at the end of package.json

Sorry, "browser": { "crypto": false, "stream": false } didn't solve my issue.
Also, I have tried patch.js from another source, but no positive result.
Please mention if any other way is there.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dwelle picture dwelle  路  3Comments

yvele picture yvele  路  4Comments

prevostc picture prevostc  路  4Comments

ehartford picture ehartford  路  3Comments

usamamashkoor picture usamamashkoor  路  4Comments