我正在尝试在 webpack 项目中使用 googleapis。每当我调用
static getApi = () => {
google.sheets('v4');
}
我收到以下错误:无法加载端点 ../apis/sheets("v4"): 找不到模块“。”
源自 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
},
导致 ENOENT: no such file or directory, scandir '/apis'
源自上述 googleapis.js 的第 62 行
最佳答案
根据这个github issue comment ,应将 googleapis Node 客户端排除在任何服务器端捆绑机制之外。
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.
关于node.js - Webpack 和 GoogleApis 端点路径问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44244359/