Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack and GoogleApis endpoint path issues

I'm trying to use googleapis in a webpack project. Whenever I invoke

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

I get the following Error: Unable to load endpoint ../apis/sheets("v4"): Cannot find module "." Originating from line 50 of googleapis/lib/googleapis.js, which is basically var Endpoint = require(endpointPath);.

I tried looking into endpointPath, but it happens to be the correct one: 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'
}

Removing the

node: {
  __dirname: true
},

results in getting a ENOENT: no such file or directory, scandir '/apis' originating from line 62 of the aforementioned googleapis.js

like image 463
Paolo Campanelli Avatar asked Nov 23 '25 23:11

Paolo Campanelli


1 Answers

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

googleapis (google-api-nodejs-client) will work in Node.js. Excluding googleapis from any server-side bundle (just let Node's module system load it for you) is the best option.

like image 157
shashi Avatar answered Nov 26 '25 17:11

shashi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!