[QUESTION] Module parse failed: Unexpected token (260:61)
romankurnovskii opened this issue · 3 comments
romankurnovskii commented
Question
Facing an issue using react
Versions
aws-jwt-verify
version: 3.1.0- react version: 18.2 (.js), in typescript version works
- react from:
npx create-react-app my-app
- node: 17
- browser: chrome
./node_modules/aws-jwt-verify/dist/esm/cognito-verifier.js 260:61
Module parse failed: Unexpected token (260:61)
You may need an appropriate loader to handle this file type.
| key: "create",
| value: function create(verifyProperties, additionalProperties) {
> return new this(verifyProperties, additionalProperties?.jwksCache);
| }
| }]);
ottokruse commented
Hi @romankurnovskii I can't reproduce this.
I did:
npx create-react-app my-app
npm i aws-jwt-verify
- Edit App.js and add import (see code below)
- Run
npm start
andnpm run build
All works fine.
Might be a versions thing. Perhaps clear your npx
cache and run create-react-app again?
// App.js
import logo from "./logo.svg";
import "./App.css";
import { CognitoJwtVerifier } from "aws-jwt-verify"; // added
// added:
const verifier = CognitoJwtVerifier.create({
userPoolId: "<user pool id>",
clientId: "<client id>",
tokenUse: "access"
});
function App() {
console.log(verifier); // added, just a dummy usage
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;
ottokruse commented
Closing for now, let us know if the issue persists.
jack-sparroow commented
I'm facing the same issue while decoding the jwt-id-token
on FE.
I have solved it (temporarily) using this.
JSON.parse(atob(token.split(".")[1]))