2017-05-29 40 views
3

我試圖在webpack項目中使用googleapis。每當我調用Webpack和GoogleApis端點路徑問題

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

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

我試圖尋找到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'

+0

您是否找到解決此問題的解決方案? – shashi

回答

1

根據此github issue comment,應該從任何服務器端捆綁機制中排除googleapis節點客戶端。

googleapis(google-api-nodejs-client)將在Node.js中工作。從任何服務器端軟件包中排除 googleapis(只需讓Node的模塊系統 爲您加載)是最佳選擇。