【问题标题】:Webpack and GoogleApis endpoint path issuesWebpack 和 GoogleApis 端点路径问题
【发布时间】:2017-10-29 20:57:19
【问题描述】:

我正在尝试在 webpack 项目中使用 googleapis。每当我调用

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

我得到以下Error: Unable to load endpoint ../apis/sheets("v4"): Cannot find module "." 源自googleapis/lib/googleapis.js的第50行,基本上就是var Endpoint = require(endpointPath);

我尝试查看 endpointPath,但它恰好是正确的:node_modules/googleapis/apis/sheets/v4

我的 webpack.config.js 如下所示:

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

删除

node: {
  __dirname: true
},

导致从上述 googleapis.js 的第 62 行获得 ENOENT: no such file or directory, scandir '/apis'

【问题讨论】:

  • 您找到解决此问题的方法了吗?

标签: node.js webpack google-api google-api-client webpack-2


【解决方案1】:

根据github issue comment,应将 googleapis 节点客户端排除在任何服务器端捆绑机制之外。

googleapis (google-api-nodejs-client) 将在 Node.js 中工作。排除 来自任何服务器端捆绑包的 googleapis(只需让 Node 的模块系统 为您加载)是最好的选择。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-18
    • 1970-01-01
    • 2017-01-31
    • 2021-03-20
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    • 2011-03-29
    相关资源
    最近更新 更多