gpt4 book ai didi

javascript - googleapis npm 模块和 webpack bundle 错误

转载 作者:太空宇宙 更新时间:2023-11-04 01:25:34 25 4
gpt4 key购买 nike

我尝试在扩展程序的后台从 Firebase 获取远程配置。

我使用 npm 安装了 googleapis 模块,并使用 webpack 来编译和捆绑文件。当我尝试在我的 js 文件中导入 googleapis 时:

从“googleapis”导入 {google};

并使用它: const jwtClient = new google.auth.JWT(...);

我在控制台中显示了几个错误:

ERROR in ./~/googleapis/build/src/googleapis.js
Module parse failed: /node_modules/googleapis/build/src/googleapis.js Unexpected token (81:10)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (81:10)
ERROR in ./~/googleapis-common/build/src/authplus.js
Module parse failed: /node_modules/googleapis-common/build/src/authplus.js Unexpected token (32:10)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (32:10)

我尝试在 webpack 配置中使用外部函数从包编译中排除 googleapis,但没有成功

    externals: {
googleapis: 'googleapis'
},

带有 babel 配置加载器的 webpack :

loaders: [{
loader: "babel-loader",
test: /\.jsx?$/,
query: {
plugins: ['transform-runtime'],
presets: ['es2015', 'react'],
}
}]

最佳答案

这似乎是 googleapis 的一个已知问题: https://github.com/googleapis/google-api-nodejs-client/issues/1270#issuecomment-412361803

似乎有一个一年前的 PR 修复了这个问题,但同样......它不知道是否/何时它会甚至可以合并到 master 分支。

如果可能,我建议尝试使用此库作为 CDN 托管依赖项: https://unpkg.com/googleapis@42.0.0/build/src/googleapis.js

与: https://www.npmjs.com/package/webpack-cdn-inject

关于javascript - googleapis npm 模块和 webpack bundle 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57654497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com