-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Error: Cannot find module '#node-web-compat' #69
Comments
Just saw that this is a duplicate of #66 |
Just ran (a slightly modified version of) your code with npx ts-node-dev index.ts
[INFO] 08:56:57 ts-node-dev ver. 1.1.8 (using ts-node ver. 9.1.1, typescript ver. 4.6.3) The modified version of your code ( import { CognitoJwtVerifier } from 'aws-jwt-verify';
import { JwtExpiredError } from 'aws-jwt-verify/error';
class UnauthorizedError extends Error {}
class TokenExpiredError extends Error {}
export const getToken = (authorization: any): string => {
if (!authorization || authorization.split(' ')[0] !== 'Bearer') {
throw new UnauthorizedError('No token provided');
}
const token = authorization.split(' ')[1];
return token;
};
export const verifyToken = async (authorization: any): Promise<any> => {
const verifier = CognitoJwtVerifier.create({
userPoolId: process.env.COGNITO_USER_POOL_ID as string,
clientId: process.env.COGNITO_CLIENT_ID as string,
tokenUse: 'access',
});
try {
const token = getToken(authorization);
const payload = await verifier.verify(token);
return payload;
} catch (e: any) {
if (e instanceof JwtExpiredError) {
throw new TokenExpiredError();
} else {
throw new UnauthorizedError(e.message);
}
}
}; // tsconfig.json
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
}
} |
Hi @ottokruse and @hakanson thanks for the quick reply! When I start the development env, this is the output: [INFO] 09:45:22 ts-node-dev ver. 1.1.8 (using ts-node ver. 9.1.1, typescript ver. 4.5.4)
Error: Cannot find module '#node-web-compat'
Require stack:
... The {
"compilerOptions": {
"baseUrl": ".",
"declaration": true,
"declarationMap": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"incremental": true,
"lib": ["es7"],
"module": "commonjs",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noImplicitAny": false,
"noImplicitReturns": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"outDir": "dist",
"resolveJsonModule": true,
"sourceMap": true,
"strict": true,
"strictPropertyInitialization": false,
"target": "es2017",
"typeRoots": ["./node_modules/@types"],
"types": ["reflect-metadata", "node"],
"useUnknownInCatchVariables": true,
},
"include": ["src/**/*.*"],
"exclude": ["node_modules", "src/**/*.test.ts", "**/__mocks__/*", "**/__mockData__/"]
}
|
Any chance you can create a minimal express app to demonstrate and host in a GitHub repo? That would be easier for us to git clone and find the problem, then we can PR back the fix. |
Any update @Robstaa ? |
I have a similar issue. Trying to bundle my function to be deployed as a edge lambda with
Getting the following error
Edit:Downgrading to 2.1.3 seems to have resolved the issue. Although issue is present in 3.0 |
@lemiesz don't mark When do you get that error? Just tested and this CDK synths flawlessly for me: import { Stack, StackProps, aws_lambda_nodejs } from "aws-cdk-lib";
import { Construct } from "constructs";
import * as path from "path";
export class JwttestStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const secureInterceptorNodejsFunction =
new aws_lambda_nodejs.NodejsFunction(
this,
"SecureInterceptorNodejsFunction",
{
bundling: {
define: {
"process.env.USER_POOL_ID": JSON.stringify("<some_id>"),
"process.env.CLIENT_ID": JSON.stringify("<some_id>"),
},
minify: true,
},
entry: path.join(
__dirname,
"../authenticate-cognito-lambda/index.js"
),
}
);
}
} |
Closing for now -- will re-open if you can provide a reproducible sample. |
Error happens during bundling. However I see you are using CDK2. I'm still on an old version (until I can upgrade the rest of our stack) I've tried both with it marked as external (as per the error message recommendation), and without. Fails same way Seems its just not compatible with monocdk |
CDK2 uses |
monocdk does indeed use esbuild. Looks like I had installed Upgrading to the a newer version of esbuild has fixed my issues... thanks! |
Currently produces this error if you run this library in Jest tests with either The workaround from https://github.com/ottokruse/jest-subpath-import/blob/main/jest.config.fix.js works for me. |
Describe the bug
When starting my typescript application, I immediately get the error
The stack is the following:
This is the
verifyToken.ts
file:Versions
Which version of
aws-jwt-verify
are you using?=> "^3.0.0"
Are you using the library in Node.js or in the Web browser?
=> Node.js
If Node.js, which version of Node.js are you using? (Should be at least 14)
=> 17.3.0
If using TypeScript, which version of TypeScript are you using? (Should be at least 4)
=> "^4.5.4"
Also, to run the application in dev I am using
ts-node-dev
("^1.1.8")The text was updated successfully, but these errors were encountered: