gax-nodejs: (Reopen PLEASE) Missing dependency `request` causes an error when using Google Cloud's Vision API

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

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

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 7
  • Comments: 16 (5 by maintainers)

Most upvoted comments

Looking at this issue, I guess that we can come here every year and celebrate google-gax using deprecated dependency. This year marks 4th request deprecation anniversary 🥳

Import trace for requested module:
./node_modules/google-gax/build/src/streamingRetryRequest.js
./node_modules/google-gax/build/src/streamingCalls/streaming.js
./node_modules/google-gax/build/src/index.js
./node_modules/@google-cloud/logging/build/src/index.js
./node_modules/@google-cloud/logging-winston/build/src/common.js
./node_modules/@google-cloud/logging-winston/build/src/index.js

This still seems to be an issue for any google-gax module using request which is depricated since 2020. npm request.

As of Feb 11th 2020, request is fully deprecated. No new changes are expected land. In fact, none have landed for some time.

Why this is closed? request is deprecated for 4 years now btw

Bump should we create a new issue to reopen this one?

@summer-ji-eng I think this should be re-opened. I don’t think it is just the OP’s serverless setup because I am hitting it using only Google stuff + webpack (and I don’t think webpack is at fault). To me it looks like google-gax did not install the parallel dependency of retry-request known as request (as shown on the npm page for retry-request). I am hitting this when adding webpack to firebase functions, i.e. right after firebase init functions, choosing typescript, and using the built-in hello world example.

// src/index.ts
import {https, logger} from "firebase-functions/v1";

export const helloWorld = https.onRequest((request, response) => {
  logger.info("Hello logs!", {structuredData: true});
  response.send("Hello from Firebase!");
});
// webpack.config.js
const glob = require('glob');
const path = require('path');

module.exports = function () {
  const entry = {};
  glob.sync("./src/*.ts").forEach(function (file) {
    const { name } = path.parse(file);
    entry[name] = file;
  });

  return {
    entry,
    mode: 'production',
    module: {rules: [{
      test: /\.tsx?$/,
      use: 'ts-loader',
      exclude: /node_modules/
    }]},
    output: {
      clean: true,
      filename: '[name].bundle.js',
      library: '[name]',
      libraryTarget: 'umd',
      path: path.resolve(__dirname, 'dist'), // deliberately not lib for now
    },
    target: 'node'
  };
};

Commands: firebase init funcitons choose typescript project and go into the functions directory Do basic installs: npm i --save-dev webpack webpack-cli ts-loader Run npx webpack and get the following:

...
WARNING in ./node_modules/retry-request/index.js 74:21-39
Module not found: Error: Can't resolve 'request' in '/home/chrischiasson/crto/functions/node_modules/retry-request'
 @ ./node_modules/google-gax/build/src/streamingCalls/streaming.js 22:21-45
 ...

Running npm i request makes this go away.

Also bumping this to be reopened please. Should just be using fetch in this day and age

Deployment with Cloudflare pages is also impacted.

ℹ Building Nitro Server (preset: cloudflare-pages)                                                                            nitro 11:28:26 PM

[nitro 11:28:30 PM]  ERROR  Error: Cannot resolve "request" from "/Users/.../node_modules/google-gax/build/src/streamingRetryRequest.js" and externals are not allowed!


undefined


[11:28:30 PM]  ERROR  Cannot resolve "request" from "/Users/.../node_modules/google-gax/build/src/streamingRetryRequest.js" and externals are not allowed!

  at Object.resolveId (node_modules/nitropack/dist/shared/nitro.4ea992bc.mjs:1973:17)
  at async PluginDriver.hookFirstAndGetPlugin (node_modules/rollup/dist/es/shared/node-entry.js:18539:28)
  at async resolveId (node_modules/rollup/dist/es/shared/node-entry.js:17208:26)
  at async ModuleLoader.resolveId (node_modules/rollup/dist/es/shared/node-entry.js:17622:15)
  at async node_modules/@rollup/plugin-commonjs/dist/es/index.js:785:16
  at async Promise.all (index 1)
  at async node_modules/@rollup/plugin-commonjs/dist/es/index.js:777:32
  at async rewriteRequireExpressionsAndGetImportBlock (node_modules/@rollup/plugin-commonjs/dist/es/index.js:1354:28)
  at async transformCommonjs (node_modules/@rollup/plugin-commonjs/dist/es/index.js:1928:23)
  at async transform (node_modules/rollup/dist/es/shared/node-entry.js:17540:16) 

still an issue

@tferrerm have you tried on the links I shared before? It is not gax issue, I assume that it is the serverless or webpack dependency config issue.

Is there any fix for it?