【发布时间】:2019-10-03 14:05:28
【问题描述】:
我正在构建一个使用 Webpack 进行构建过程的 Angular2 应用程序。我想在我的应用中创建一个 Google oauth 登录功能。所以我已经从 npm 安装了 googleapi 包。但是我在将这个包导入我的应用程序时遇到了一些问题。
我正在尝试import * from 'googleapi';,但这会使应用程序崩溃并显示消息:
Uncaught ReferenceError: require is not defined
这是我的 System.config:
System.config({
map: {
rxjs: 'node_modules/rxjs',
googleapis: 'node_modules/googleapis'
},
meta: {
googleapis: { format: 'commonjs' }
},
packages: {
app: {
format: 'register',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
});
System.import('app/contacts-app').then(null, console.error.bind(console));
如何在我的应用中包含这个包?
【问题讨论】:
-
您是否尝试设置包
googleapis而不是元?您是否将 apis 文件作为脚本包含在 html 中(您不应该)?
标签: javascript google-api npm angular