typescript error: @sentry/serverless requires gcp dev denpendency even if you only use AWS lambda
Package + Version
- [ ]
@sentry/browser - [x]
@sentry/node - [ ]
raven-js - [ ]
raven-node(raven for node) - [x] other: @sentry/serverless
Version:
5.27.1
Description
I added @sentry/serverless to an existing lambda functions app and I got this error.
node_modules/@sentry/serverless/dist/gcpfunction/cloud_events.d.ts:1:68 - error TS2307: Cannot find module '@google-cloud/functions-framework/build/src/functions' or its corresponding type declarations.
Just ran into the same problem, with version 5.26.0
Only way I could fix it for now was adding @google-cloud/function-framework as a dependency
The error comes from typescript, but other than that the lib seems to work fine
Same here
Ran into this as well. Makes upgrading impossible.
Same experience as @teddav on 5.26 and 5.27.
Also running into this on 5.27 😄
Downgrading to 5.24 worked for me
We can't deploy because of this issue :-/
You guys could/should fix this by breaking this out into two packages. One for GCP and one for AWS and including the dependencies there...
Got this error after adding @google-cloud/functions-framework as dev dependency.
c:/code/email-validation-service/node_modules/@google-cloud/functions-framework/build/src/functions.d.ts(1,26): error TS7016: Could not find a declaration file for module 'express'. 'c:/code/email-validation-service/node_modules/express/index.js' implicitly has an 'any' type.
After adding @types/express the compiler was content.
thanks for the fix! I see that it's not released yet though. do you think we could release this soon?
Has this been released? I'm using v6.2.2 and getting similar error:
WARNING in ./node_modules/@sentry/serverless/esm/awslambda.js 42:15-39
Critical dependency: the request of a dependency is an expression
@ ./node_modules/@sentry/serverless/esm/index.js 2:0-41 4:0-34
@ ./src/handlers/slack.ts 3:21-50
WARNING in ./node_modules/@sentry/serverless/esm/awslambda.js 45:11-71
Critical dependency: the request of a dependency is an expression
@ ./node_modules/@sentry/serverless/esm/index.js 2:0-41 4:0-34
@ ./src/handlers/slack.ts 3:21-50
WARNING in ./node_modules/@sentry/serverless/esm/awslambda.js 45:19-26
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
@ ./node_modules/@sentry/serverless/esm/index.js 2:0-41 4:0-34
@ ./src/handlers/slack.ts 3:21-50
WARNING in ./node_modules/@sentry/serverless/esm/google-cloud-grpc.js 17:30-51
Module not found: Error: Can't resolve 'google-gax' in '/Users/kyledecot/code/tabulous-notification/node_modules/@sentry/serverless/esm'
@ ./node_modules/@sentry/serverless/esm/gcpfunction/index.js 2:0-55 11:8-23
@ ./node_modules/@sentry/serverless/esm/index.js 3:0-45 4:0-34
@ ./src/handlers/slack.ts 3:21-50
WARNING in ./node_modules/@sentry/serverless/esm/google-cloud-http.js 17:33-64
Module not found: Error: Can't resolve '@google-cloud/common' in '/Users/kyledecot/code/tabulous-notification/node_modules/@sentry/serverless/esm'
@ ./node_modules/@sentry/serverless/esm/gcpfunction/index.js 3:0-55 10:8-23
@ ./node_modules/@sentry/serverless/esm/index.js 3:0-45 4:0-34
@ ./src/handlers/slack.ts 3:21-50
I'm also getting a bunch of warnings. I'm bundling code using webpack, everything. works, but this is ugly (at least I think it works).
As I understand sentry and others libs are doing something like this - const dep = require("./" + variable). This causes webpack to be confused.
Warnings:
WARNING in ./node_modules/@sentry/serverless/esm/awslambda.js 42:15-39
Critical dependency: the request of a dependency is an expression
@ ./node_modules/@sentry/serverless/esm/index.js 2:0-41 4:0-34
@ ./src/lambda.ts
WARNING in ./node_modules/@sentry/serverless/esm/awslambda.js 45:11-71
Critical dependency: the request of a dependency is an expression
@ ./node_modules/@sentry/serverless/esm/index.js 2:0-41 4:0-34
@ ./src/lambda.ts
WARNING in ./node_modules/@sentry/serverless/esm/awslambda.js 45:19-26
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
@ ./node_modules/@sentry/serverless/esm/index.js 2:0-41 4:0-34
@ ./src/lambda.ts
WARNING in ./node_modules/@sentry/serverless/esm/google-cloud-grpc.js 17:30-51
Module not found: Error: Can't resolve 'google-gax' in '/Users/arturs/Projects/zumvie-people/backend/node_modules/@sentry/serverless/esm'
@ ./node_modules/@sentry/serverless/esm/gcpfunction/index.js 2:0-55 11:8-23
@ ./node_modules/@sentry/serverless/esm/index.js 3:0-45 4:0-34
@ ./src/lambda.ts
WARNING in ./node_modules/@sentry/serverless/esm/google-cloud-http.js 17:33-64
Module not found: Error: Can't resolve '@google-cloud/common' in '/Users/arturs/Projects/zumvie-people/backend/node_modules/@sentry/serverless/esm'
@ ./node_modules/@sentry/serverless/esm/gcpfunction/index.js 3:0-55 10:8-23
@ ./node_modules/@sentry/serverless/esm/index.js 3:0-45 4:0-34
@ ./src/lambda.ts
WARNING in ./node_modules/express/lib/view.js 81:13-25
Critical dependency: the request of a dependency is an expression
@ ./node_modules/express/lib/application.js 22:11-28
@ ./node_modules/express/lib/express.js 18:12-36
@ ./node_modules/express/index.js 11:0-41
@ ./src/lambda.ts 31:34-52
WARNING in ./node_modules/type-graphql/dist/helpers/loadResolversFromGlob.js 11:46-63
Critical dependency: the request of a dependency is an expression
@ ./node_modules/type-graphql/dist/utils/buildSchema.js 6:32-75
@ ./node_modules/type-graphql/dist/utils/index.js 4:20-44
@ ./node_modules/type-graphql/dist/index.js 10:21-39
@ ./src/schema.ts 4:23-46
@ ./src/lambda.ts 37:15-34
By adding the webpack-ignore-dynamic-require plugin I got rid of Critical dependency: the request of a dependency is an expression
.
But Module not found stayed:
WARNING in ./node_modules/@sentry/serverless/esm/google-cloud-grpc.js 17:30-51
Module not found: Error: Can't resolve 'google-gax' in '/Users/arturs/Projects/zumvie-people/backend/node_modules/@sentry/serverless/esm'
@ ./node_modules/@sentry/serverless/esm/gcpfunction/index.js 2:0-55 11:8-23
@ ./node_modules/@sentry/serverless/esm/index.js 3:0-45 4:0-34
@ ./src/lambda.ts
WARNING in ./node_modules/@sentry/serverless/esm/google-cloud-http.js 17:33-64
Module not found: Error: Can't resolve '@google-cloud/common' in '/Users/arturs/Projects/zumvie-people/backend/node_modules/@sentry/serverless/esm'
@ ./node_modules/@sentry/serverless/esm/gcpfunction/index.js 3:0-55 10:8-23
@ ./node_modules/@sentry/serverless/esm/index.js 3:0-45 4:0-34
@ ./src/lambda.ts
By installing the @google-cloud/common and google-gax I get rid of all the errors. I think installing these packages can prevent some undefined behaviour, while it is not fixed.
This is not cool solution, fingers crossed that there will be no runtime errors.
I'm using @sentry/serverless 6.18.2 and I'm still getting those errors. Why was this ticket closed? I'm using AWS as my cloud provider and I don't need/want the GCP packages to be installed just to bypass this error.
WARNING in ./node_modules/@sentry/serverless/esm/google-cloud-grpc.js 18:30-51 Module not found: Error: Can't resolve 'google-gax'
WARNING in ./node_modules/@sentry/serverless/esm/google-cloud-http.js 18:33-64 Module not found: Error: Can't resolve '@google-cloud/common'
I'm also getting the same error. We use AWS and it's not great to have to install packages for other providers to get @sentry/serverless to compile properly.
@HazAT @kamilogorek I'm still facing this 2 years later, should this issue be reopen?
WARNING in ../../node_modules/.pnpm/@[email protected]/node_modules/@sentry/serverless/esm/google-cloud-http.js 10:27-58
Module not found: Error: Can't resolve '@google-cloud/common' in '/Users/work/cv/cv/node_modules/.pnpm/@[email protected]/node_modules/@sentry/serverless/esm'
@ ../../node_modules/.pnpm/@[email protected]/node_modules/@sentry/serverless/esm/gcpfunction/index.js 3:0-55 10:6-21
@ ../../node_modules/.pnpm/@[email protected]/node_modules/@sentry/serverless/esm/index.js 2:0-45 3:0-34
@ ../../libs/lambda/src/sentry/sentry.ts 1:0-4:28 6:0-35 6:0-35 9:9-31 16:9-33
@ ../../libs/lambda/src/sentry/index.ts 5:0-35 9:2-23 17:0-18 22:2-23 29:4-25 46:2-23 64:9-37
@ ../../libs/lambda/src/index.ts 6:0-34 6:0-34
@ ./src/lambda.js 2:0-50 7:23-34
yea it's definitely still an issue. i imagine breaking dependency chain apart is quite a task without creating separate libs for each cloud provider 😉. you can place all of the libs typescript errors out for in the webpack externals array to get around the typescript issue. webpack will still throw warnings but everything seems to work as intended.
const path = require("path");
module.exports = {
mode: process.env.NODE_ENV,
entry: "./src/index.ts",
externals: [
"aws-sdk",
"aws-sdk/global",
"google-gax",
"@google-cloud/common"
],
output: {
path: path.resolve(__dirname, "dist"),
filename: "index.js",
library: {
name: "handler",
type: "umd"
}
},
target: "node",
module: {
rules: [
{
test: /\.(js|ts)$/,
exclude: /(node_modules)/,
use: {
loader: "babel-loader"
}
}
]
}
};
or you can add @sentry/serverless in an aws lambda layer if you ARE NOT using webpack.
@HazAT this issue should definitely still be open though. unless your docs are amended to include work arounds to not bring in the whole dependency chain.
running into this now. on @sentry/serverless v7.38.0
ERROR Error: Encountered resolution error in /home/vsts/work/1/s/lambda/node_modules/@sentry/serverless/cjs/google-cloud-grpc.js for google-gax: Error: Cannot find module 'google-gax' from '/home/vsts/work/1/s/lambda/node_modules/@sentry/serverless/cjs'
at /home/vsts/work/1/s/lambda/node_modules/trace-deps/lib/trace.js:304:17
why is google-gax a dependency when this is being deployed on aws?
We're still seeing these exact same issues 3.5yrs later on v7.91.0
@HazAT do you know how to resolve/workaround or can we get this issue re-opened?