我正在使用 ReactJS、Webpack、Babel 和 Firebase 构建一个应用程序。
当我运行 webpack 以使用 babel 加载程序捆绑我的代码时,我看到以下内容被打印在许多其他行中:
[BABEL] 注意:代码生成器对“/Users/.../myproject/node_modules/firebase/lib/firebase-web.js”的样式进行了优化,因为它超过了“100KB”的最大值。
然后,当我尝试在我的应用程序中使用 require('firebase'),然后在浏览器中运行它时......浏览器会在控制台中打印出以下内容。
Uncaught TypeError: Cannot read property 'navigator' of undefined
(anonymous function) @ firebase-web.js:12
(anonymous function) @ firebase-web.js:262
__webpack_require__ @ bootstrap da2fff1ce4ea892319dc:19
aa @ PlayerStore.js:3
__webpack_require__ @ bootstrap da2fff1ce4ea892319dc:19
prop @ Player.js:19
__webpack_require__ @ bootstrap da2fff1ce4ea892319dc:19
(anonymous function) @ index.js:13
__webpack_require__ @ bootstrap da2fff1ce4ea892319dc:19
obj.__esModule.default @ bootstrap da2fff1ce4ea892319dc:39
(anonymous function) @ bootstrap da2fff1ce4ea892319dc:39
PlayerStore.js:3 是我的行:
var Firebase = require('firebase');
当我尝试加载我的应用程序时,有谁知道是什么导致了这个错误?我不确定这个错误是否开始是因为我从使用 Webpack 中的 jsx-loader 切换到了 babel,或者因为我运行了“npm update”并且我正在使用的一个包的新版本正在破坏事情。