Npm 网页包导入firebase不工作

Npm 网页包导入firebase不工作,npm,firebase,webpack,Npm,Firebase,Webpack,我在让firebase 3.0.1工作时遇到问题。我有一种感觉,这是关于我的网页设置。我的档案在下面。使用webpack dev server运行我的应用程序时,我收到错误: 未捕获类型错误:firebase.initializeApp不是函数 有趣的是,如果我放置一个调试器或var firebase=require('firebase')后的断点它似乎是一个空对象 webpack.config.js const webpack = require("webpack"); module.exp

我在让firebase 3.0.1工作时遇到问题。我有一种感觉,这是关于我的网页设置。我的档案在下面。使用webpack dev server运行我的应用程序时,我收到错误:

未捕获类型错误:firebase.initializeApp不是函数

有趣的是,如果我放置一个
调试器
var firebase=require('firebase')后的断点它似乎是一个空对象

webpack.config.js

const webpack = require("webpack");

module.exports = {
    entry: './src/index.js',
    output: {
        path: 'public',
        filename: 'bundle.js'
    },
    module: {
        loaders: [{
            test: /\.js$/,
            exclude: /node_modules/,
            loader: 'babel-loader?presets[]=es2015&presets[]=react'
        }]
    },
    plugins: process.env.NODE_ENV === 'production' ? [
        new webpack.optimize.DedupePlugin(),
        new webpack.optimize.OccurrenceOrderPlugin(),
        new webpack.optimize.UglifyJsPlugin()
    ] : []
};
var firebase = require('firebase');

var config = {
    apiKey: "AIzaSyA9gUmSBu4SZ4P9H_4lXuN1ouD_GBKq3aw",
    authDomain: "burn-56840.firebaseapp.com",
    databaseURL: "https://burn-56840.firebaseio.com",
    storageBucket: "burn-56840.appspot.com"
};
firebase.initializeApp(config);
package.json

{
  "name": "burn",
  "version": "1.0.0",
  "description": "burn messaging",
  "main": "index.js",
  "scripts": {
    "start": "if-env NODE_ENV=production && npm run start:prod || npm run start:dev",
    "start:dev": "webpack-dev-server --inline --content-base public --history-api-fallback",
    "start:prod": "webpack && firebase deploy"
  },
  "author": "James Gilchrist <james@burn.today>",
  "license": "ISC",
  "dependencies": {
    "compression": "^1.6.2",
    "express": "^4.13.4",
    "firebase": "^3.0.1",
    "if-env": "^1.0.0",
    "react": "^15.0.2",
    "react-dom": "^15.0.2",
    "react-router": "^2.4.0"
  },
  "devDependencies": {
    "babel-core": "^6.9.0",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-react": "^6.5.0",
    "webpack": "^1.13.0",
    "webpack-dev-server": "^1.14.1"
  }
}
我有一个问题,但有一个简单的解决办法:

var firebase = require('firebase/app');
这样你就得到了真正的firebase模块。但是,您现在必须要求正确加载所需的每个模块,如:

var firebase = require('firebase/app');
// all 3 are optional and you only need to require them at the start
require('firebase/auth');
require('firebase/database');
require('firebase/storage');

在我看来,当前的初始化代码有问题,看看它应该工作的源代码;不过,我还是有点像你,我使用的是browserify,而且没有在它之外进行测试,所以它可能有关联。

你知道。我确实在文档中看到firebase有这个选项。但这看起来太傻了,我甚至都没试过。感谢您的快速响应;非常感谢。