So, when i try to add jsonwebtoken to my code, VS Code says the code is fine, but the compiler fails
Can you help me why? Thanks!
Heres a part of my code:
this.http
.post<any>(`http://localhost:3000/api/login`, {
username: data.username,
password: data.password,
token: token,
})
.subscribe((response) => {
this.logError = response.error;
if (response.error == '') {
let jwtsecKey= "my key. I deleted that"
console.log(response);
console.log(jwt.sign(response, jwtsecKey))
}
});
}
}
Compiler:
./node_modules/jws/lib/verify-stream.js:8:13-30 - Error: Module not found: Error: Can't resolve 'stream' in 'C:\Users\almak\Desktop\Chatenium\Chatenium\node_modules\jws\lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
× Failed to compile.
CodePudding user response:
jsonwebtoken
is a Node.js module, its use in previous versions webpack relied upon a polyfill of the Node.js built-in modules. This most likely a) relied on slow js cryptography that isn't maintained anymore and lacks feature parity with Node's crypto and b) increased your js bundle size considerably. Webpack 5 no longer defaults to using these questionable crypto polyfill.
It is better to rely on JWT modules made to be consumed in browser environments, you can discover such modules on jwt.io under "JavaScript" libraries.