sentry-javascript: typescript error: @sentry/serverless requires gcp dev denpendency even if you only use AWS lambda

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • 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.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 14
  • Comments: 19

Commits related to this issue

Most upvoted comments

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 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

@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.

@HazAT @kamilogorek I’m still facing this 2 years later, should this issue be reopen?

WARNING in ../../node_modules/.pnpm/@sentry+serverless@6.3.6/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/@sentry+serverless@6.3.6/node_modules/@sentry/serverless/esm'
 @ ../../node_modules/.pnpm/@sentry+serverless@6.3.6/node_modules/@sentry/serverless/esm/gcpfunction/index.js 3:0-55 10:6-21
 @ ../../node_modules/.pnpm/@sentry+serverless@6.3.6/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

thanks for the fix! I see that it’s not released yet though. do you think we could release this soon?

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"
        }
      }
    ]
  }
};

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.