Content issues in Webpack and GoogleApis

I am trying to use googleapis in a webpack project. Whenever I call

static getApi = () => {
    google.sheets('v4');
}

      

I get the following Error: Unable to load endpoint ../apis/sheets("v4"): Cannot find module "."

Arises from line 50 googleapis/lib/googleapis.js

, which is basically var Endpoint = require(endpointPath);

.

I tried looking at endpointPath but it turned out to be correct: node_modules/googleapis/apis/sheets/v4

My webpack.config.js is presented below:

module.exports = {
   entry: ['babel-polyfill','./src/index.js'],
   target: 'async-node', // Improved performance in node version 6+
   node: {
     __dirname: true
   },
   output: {
     filename: './dist/bundle.js',
     libraryTarget: 'commonjs2'
   },
   module: {
     rules: [
      {
    test: /\.(graphql|gql)$/,
    exclude: /node_modules/,
    loader: 'graphql-tag/loader'
  },
  {
    test: /\.js$/,
    exclude: /(node_modules)/,
    use: {
      loader: 'babel-loader',
        options: {
          presets: ['env'],
          plugins: [require('babel-plugin-transform-class-properties')]
        }
      }
    }
  ]
  },
  devtool: 'source-map'
}

      

Deleting

node: {
  __dirname: true
},

      

results in getting a ENOENT: no such file or directory, scandir '/apis'

coming from line 62 of the aforementioned googleapis.js

+3


source to share


1 answer


As per this github comment , the googleapis node client should be excluded from any server side binding mechanism.



googleapis (google-api-nodejs-client) will work in Node.js. Aside from googleapis from any server side package (just let the node module load it for you) is the best option.

+1


source







All Articles