Skip to content
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

Missing dependency request causes an error when using Google Cloud's Vision API #1606

Closed
tferrerm opened this issue May 27, 2024 · 6 comments · Fixed by #1612
Closed

Missing dependency request causes an error when using Google Cloud's Vision API #1606

tferrerm opened this issue May 27, 2024 · 6 comments · Fixed by #1612
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@tferrerm
Copy link

Environment details

  • OS: Ubuntu 20.04 x64
  • Node.js version: v14.2.0
  • npm version: 7.24.1
  • google-gax version: 2.28.0

Steps to reproduce

  1. Create a serverless Node.js project
  2. Add the serverless-webpack plugin to your serverless.yml file and use webpack with babel to package the function that will be created
  3. Add @google-cloud/vision as a dependency
  4. Create a Node.js Google Function or AWS Lambda that makes use of the Google Vision API (e.g. do something similar to what is shown in this SafeSearch example)
  5. Attempt to build the lambda with webpack

Here's an example YML configuration file for a Lambda that uses this:

service: ${file(./config/global.json):SERVICE_NAME}
frameworkVersion: "2"

plugins:
  - serverless-webpack
  - serverless-prune-plugin

provider:
  name: aws
  runtime: nodejs14.x
  stage: ${opt:stage, 'dev'}
  # Examples loading from a local config file. Utilizes stage flag when invoked. If no --stage was passed into invocation, use the "dev" configuration
  region: ${file(./config/${opt:stage, 'dev'}.json):REGION}
  stackName: ${file(./config/${opt:stage, 'dev'}.json):IDENTIFER_BASE}-cfStack-stackname

custom:
  webpack:
    packager: "yarn"
    includeModules:
      forceExclude:
        - aws-sdk
  somethingTopicARN:
    Fn::ImportValue: 'trust-sns-${opt:stage,self:provider.stage}-something'
  somethingRoleARN:
    Fn::ImportValue: 'trust-sns-${opt:stage,self:provider.stage}-something-Role'
  anotherthingTopicARN:
    Fn::ImportValue: 'trust-sns-${opt:stage,self:provider.stage}-anotherthing'

package:
  individually: true
  patterns:
    - '!node_modules/@aws-sdk/**'
    - '!node_modules/aws-sdk/**'
    - '!node_modules/pretty-format/**'
    - '!node_modules/typescript/**'
    - '!node_modules/@typescript-eslint/**'
    - '!node_modules/prettier/**'
    - '!node_modules/pretty-format/**'
    - '!node_modules/@babel/**'

    - '!tests/**'
    - '!sns-serverless.yml'
    - '!s3-temp-trigger-serverless.yml'
    - '!coverage/**'
    - '!.circleci/**'
    - '!README.md'

functions:
  vertexApi:
    handler: src/something-service/handler/lambdaGcloudWorker.handler
    name: trust-use1-${opt:stage, 'dev'}-lambda-vertex
    role: ${self:custom.somethingRoleARN}
    memorySize: 1024
    timeout: 900
    maximumRetryAttempts: 0
    environment:
      NODE_ENV: ${file(./config/${opt:stage, 'dev'}.json):STAGE}
      s3PreImageBucket: 
        Ref: PreProcessingBucket
    events:
      - sns: 
          arn: { "Fn::Join" : ["", ["${self:custom.somethingTopicARN}"] ]  }
          topicName: 'trust-use1-${opt:stage,self:provider.stage}-sns-something'

  anotherVertexApi:
    handler: src/another-service/handler/lambdaWorker.handler
    name: trust-use1-${opt:stage, 'dev'}-lambda-vertex-2
    role: ${self:custom.imageModerationRoleARN}
    memorySize: 1024
    timeout: 900
    maximumRetryAttempts: 0
    environment:
      NODE_ENV: ${file(./config/${opt:stage, 'dev'}.json):STAGE}
      s3PreImageBucket: 
        Ref: PreProcessingBucket
    events:
      - sns: 
          arn: { "Fn::Join" : ["", ["${self:custom.anotherTopicARN}"] ]  }
          topicName: 'trust-use1-${opt:stage,self:provider.stage}-sns-anotherthing'

# you can add CloudFormation resource templates here
resources:
  Resources:
    PreProcessingBucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: 'trust-use1-${opt:stage,self:provider.stage}-s3'
        AccessControl: Private
        PublicAccessBlockConfiguration:
          BlockPublicAcls: true
          BlockPublicPolicy: true
          IgnorePublicAcls: true
          RestrictPublicBuckets: true        
        BucketEncryption:
          ServerSideEncryptionConfiguration:
            - ServerSideEncryptionByDefault:
                SSEAlgorithm: AES256
        LifecycleConfiguration:
          Rules:
            -
              ExpirationInDays: 1
              Status: Enabled
              Id: "Deleted in 1 Day"
              NoncurrentVersionExpirationInDays: 1


  Outputs:        

    S3ImageBucket:
      Value:
        Ref: PreProcessingBucket
      Export:
        Name: trust-s3-${opt:stage,self:provider.stage}-vertex

Error

WARNING in ./node_modules/retry-request/index.js 74:21-39
Module not found: Error: Can't resolve 'request' in '/home/user/project/node_modules/retry-request'
 @ ./node_modules/@google-cloud/vision/node_modules/google-gax/build/src/streamingCalls/streaming.js 22:21-45
 @ ./node_modules/@google-cloud/vision/node_modules/google-gax/build/src/index.js 64:18-55
 @ ./node_modules/@google-cloud/vision/build/src/helpers.js 24:12-33
 @ ./node_modules/@google-cloud/vision/build/src/index.js 31:16-36
 @ ./src/image-service/handler/lambdaGcloudWorker.js 38:15-46

Possible solution

Add the package request as a dependency of the project here given you've included retry-request

Workaround

Add request as a dependency of the serverless project by running npm install request --save

Also: Issue #1149 was closed for no good reason and we had lots of further comments of people with the same bug.
The request library has reached end of life so the ideal solution would be to get rid of it completely in this project.

@tferrerm tferrerm added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels May 27, 2024
@jahabeebs
Copy link

Also facing this issue when using ^6.4.0 of @google-cloud/language w/Next.js

@teamclouday
Copy link

@google-cloud/compute with nextjs is having the same issue

@Anisotropic
Copy link

Faced the same issue while using firebase with nodeJs

@leahecole
Copy link
Contributor

Apologies for the closure, reopen, re closure. Some more info:

Part of retry-request functionality has been migrated into gax with the goal of not needing to depend on retry-request at all in a future major version. Until #1612, we also had that extremely outdated require('request') in there, which had come from retry-request. That has since been cleaned up both in gax and in retry-request. Gax now depends on retry-request versions that no longer have this problem.

I just verified, and vision depends on a version of gax where this has since been fixed, as do the latest versions of google-cloud-language

@jahabeebs
Copy link

google-cloud-language

Hi @leahecole, I'm using the latest version of @google-cloud/language (6.4.0) and this issue is still present. Are you saying in future releases it'll include your #1612 fix and we won't have to keep request as a dependency anymore?

@leahecole
Copy link
Contributor

Hi @jahabeebs thank you for the update, good to know! Yes, the next release when we cut it should include #1612, and our automation should push that out to client libraries soon - I'll poke some folks for reviews today to make sure everything is okay with cutting that release hopefully today. Request shouldn't have to be a dependency once that happens especially given that that outdated line of code is removed from the version of retry-request found in gax already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants