Angular2-jwt: SystemJS js-base64 not found

Created on 9 Oct 2016  Â·  29Comments  Â·  Source: auth0/angular2-jwt

Hey, I already had angular2-jwt installed and it was working well but for some reason I reinstalled the npm and it started to give this error. Then I installed the js-base64 manually with the command "npm i save-- @types/js-base64" and then the error changed to:

"(index):31 Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:3000/buffer ...
Error loading http://localhost:3000/buffer as "buffer" from http://localhost:3000/node_modules/js-base64/base64.js"

In this moment I have the following dependencies in my package.json:

"@types/js-base64": "^2.1.4", "angular2-jwt": "^0.1.24", "js-base64": "^2.1.9",

Any idea of what is happenning?

Thanks for any help!

Most helpful comment

@danielserrao looking into this. For now you should be ok if you pin to v0.1.23.

All 29 comments

If I put "angular2-jwt": "0.1.19" and reinstall the npm, there is another error:

"Error: (SystemJS) core_1.provide is not a function
TypeError: core_1.provide is not a function
at Object.eval (http://localhost:3000/node_modules/angular2-jwt/angular2-jwt.js:206:12)"

@danielserrao looking into this. For now you should be ok if you pin to v0.1.23.

I too am facing this issue. I have tried with 0.1.22 and still seem to be getting the issue when I bundle my dependencies (with SystemJS Builder).

I've been having issues with 0.1.24 as well. I was getting errors related to js-base64 that seemed to related to node_modules/buffer not existing, so I tried adding "buffer": "^5.0.0" in my package.json. This fixed the issues locally, but then I started having issues with a remote deploy where tokenNotExpired was throwing a no decode method for undefined exception. Pinning to v0.1.23 fixed that issue.

We are also facing this problem in our build with 0.1.24

I have exactly the same problem, does anyone know the solution. Is JWT was raised to angular2 ?

node_modules/angular2-jwt/angular2-jwt.ts(1,24): error TS2307: Cannot find module 'js-base64'

same problem here...
"angular2-jwt": "^0.1.24", and also with 0.1.23
"buffer": "^5.0.0",
"@types/js-base64": "^2.1.4",

[12:32:02] 'build.bundles.app' errored after 1.44 s
[12:32:02] Error on fetch for js-base64.js at file:///C:/CLOUD/Login/node_modules/js-base64.js
        Loading angular2-jwt/angular2-jwt.js
        Loading dist\tmp\app\app.module.js
        Loading dist\tmp\app\main.js
        Error: ENOENT: no such file or directory, open 'C:\CLOUD\Login\node_modules\js-base64.js'
    at Error (native)
[12:32:02] 'build.prod' errored after 26 

edit:

got it working with
0.1.23
had to remove @types/js-base64
imports shoud look like 'angular2-jwt/angular2-jwt';

@georgeedwards confirm the version npm installed and get back to us.
@bpblack My bad. I added the dep and ran unit tests, they ran okay and I didn't realise that the lib tries to use buffer if you're in a 'node' environment.

I tracked the issue down to SystemJS doesn't manage your transitive dependencies for you.

If you add the following to your SystemJS config in the map section:

      'js-base64':'npm:js-base64/base64.js',
      'buffer':'@empty'

If you're using the Angular CLI, I think you might need to also tell angular about js-base64. I haven't really used the CLI, and I'm a webpack user myself, so these sorts of things don't generally come up.

If something needs to be added elsewhere, please let me know so I can update the docs (I'm already going to update them for SystemJS).

@escardin npm: 3.10.8

@georgeedwards Ah, I meant of angular2-jwt

Facing the same issue on '0.1.23' or '0.1.24', I checked the angular2-jwt.ts and it seems like it can't find a reference to js-base64.

var map = { 
"angular2-jwt": "node_modules/angular2-jwt",
}

var package = { 
'angular2-jwt':            { main: './angular2-jwt.js', defaultExtension: 'js' },
}

I have had the same issue.

@escardin fix has seemed to work.

I'm using ionic2 RC, ionic serve seems fine. But goes with the ionic build, we have this error:
node_modules/angular2-jwt/angular2-jwt.ts:1:24: Cannot find module 'js-base64'.
Seems we have the same problem here. Any idea?

Thanks

@jayhuang75 we're going to find a better way to handle this for SystemJS users. In the meantime you should be able to use v0.1.23 without error.

I'm seeing this issue using also, and I'm using Webpack.

ERROR in [default] ../node_modules/angular2-jwt/angular2-jwt.ts:1:23 
Cannot find module 'js-base64'.

@chenkie Thanks for the reply, I think we met last time in ng-conf. :)
So I found the solution for this. Basically, dependencies we have to add the js-base64 and in devDependencies we have to add the @types/js-base64, then this error is not more there when we using ionic build. Hope this can help someone is updating their ionic2 app to RC.

Thanks

@jayhuang75 Adding js-base64 to dependencies and @types/js-base64 to devDependencies also solved my issue in Webpack. Thanks for the tip!

Happy to helping!

@jayhuang75 that's right, we ate the food trucks! Hope to see you at ng-conf again in 2017 :)

@escardin wrote up the config required to fix this problem in the readme https://github.com/auth0/angular2-jwt/commit/6b5816dc4f09f5603f7ea6ca9376c0650b80354b#diff-04c6e90faac2675aa89e2176d2eec7d8

Perhaps this thread can now be closed?

@Bucabug Hi, I'm facing this problem too, but i'm using angular2 seed from mgechev ans there is not a systemjs.config then I don't know how to solve this.

Tried @karelwgonzalez astuce to add js-base64 and @types but doesn't work.

Any help please?

edit: Working on my windows but not on my linux

edit2: Fixed on linux by installing node package buffer

@dragonnblack I got the dev build working that way, but the production build is not. Were you able to get the production build working?

@iherbivore when you launch like 'npm start --env dev' it's ok but not with 'npm star --env prod' ?
Which OS ?

Yeah the build.prod version... I can't get the mappings right. I think it
needs to go in the shims since it is a 3rd party dependency. But I think
that puts the Base64 in the global scope already but the angular2-jwt is
trying to get Base64 from js-base64 and I can't get that mapped out
right. This is a lot of effort suddenly. I might need to try the other jwt
package.

On Thu, Oct 13, 2016, 12:06 Stessy Mougeot [email protected] wrote:

@iherbivore https://github.com/iherbivore when you launch like 'npm
start --env dev' it's ok but not with 'npm star --env prod' ?
Which OS ?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/auth0/angular2-jwt/issues/192#issuecomment-253559443,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADHaneQ6XHT3OqYOP2vvUb4AmwVlup2Zks5qzlcRgaJpZM4KR99u
.

@dragonnblack I'm also using angular2 seed from mgechev but when I try to run the prod building, it tells me it can't fetch "_node_modules/js-base64.js_" (from "_angular2-jwt/angular2-jwt.js_").

Can you precise what you've done to solve your issue?

@mc100s try to npm install --save js-base64 and buffer, that fixed for me

for me this fixed the issue for systemJs config users.
I also installed js-base64 (npm install js-base64 --save-dev).
`var map = {

"angular2-jwt": "node_modules/angular2-jwt",
"js-base64": "node_modules/js-base64",
'buffer':'@empty',

};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {

'angular2-jwt':            { main: './angular2-jwt.js', defaultExtension: 'js' },
'js-base64':            { main: './base64.js', defaultExtension: 'js' },

};`

Solved by #201

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tekkudoc picture tekkudoc  Â·  5Comments

mahendra2125 picture mahendra2125  Â·  4Comments

fabiodomingues picture fabiodomingues  Â·  5Comments

getglad picture getglad  Â·  5Comments

dmitrybz picture dmitrybz  Â·  4Comments