Node-jsonwebtoken: Couldn't import script

Created on 24 May 2017  路  7Comments  路  Source: auth0/node-jsonwebtoken

I have a ReactNative project where I try to use the jsonwebtoken module.

import * as jwt from 'jsonwebtoken';
var decodedToken = jwt.decode(token.payload);

But I end up with the following error when I run the project:

[Warning] Couldn't import script at <http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false>.
Debugging won't work: Try reloading the JS from inside the app, or Reconnect the debugger:
{"from":"C:\\Users\\men\\Documents\\GitHub\\FLEX-mobile\\node_modules\\jws\\lib\\sign-stream.js","to":"stream","message":
"Unable to resolve module `stream` from `C:\\Users\\men\\Documents\\GitHub\\FLEX-mobile\\node_modules\\jws\\lib\\sign-stream.js`:
Module does not exist in the module map or in these directories:
C:\\Users\\men\\Documents\\GitHub\\FLEX-mobile\\node_modules

This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
1. Clear watchman watches: `watchman watch-del-all`.
2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
3. Reset packager cache: `rm -fr $TMPDIR/react-*` or `npm start -- --reset-cache`.","name":"UnableToResolveError","type":"UnableToResolveError","errors":[{}]}

If I remove these 2 lines of code the project runs perfectly. I have tried the suggestions at the end of the message but nothing I do seems to fix it.

The project is run from inside PHPStorm (IntelliJ) but I get the same error if I run the project from the command line.

Most helpful comment

same need, same issue... not so happy with the "base-64" solution.

All 7 comments

@menderleit this library is more oriented to node not react-native so probably the packager cannot bundle it. What are you trying to accomplish?

@hzalaz his question is obvious, how do we use jwt in react-native app?

@hzalaz @Tom29 I'm just trying to decode the token into a javascript object.
I couldn't get jsonwebtoken to work, but I managed to decode it by using the base-64 library.
https://www.npmjs.com/package/base-64

import base64 from 'base-64';
const parts = token.split('.');
let decodedToken = base64.decode(parts[1]);
decodedToken = JSON.parse(decodedToken);

same need, same issue... not so happy with the "base-64" solution.

Would love this library to work with RN!

brought here because of crypto dependency issue...I'm assuming we can fix the crypto issue by referencing the built in node_module, but how do you even do that?

Closing this as stale.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cope picture cope  路  4Comments

glowlabs picture glowlabs  路  3Comments

Teebo picture Teebo  路  4Comments

salali picture salali  路  5Comments

Sir-hennihau picture Sir-hennihau  路  4Comments