【发布时间】: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