javascript – 带有Node和Webpack的Firebase无法正常工作 – 无法读取未定义的属性“navigator”

前端之家收集整理的这篇文章主要介绍了javascript – 带有Node和Webpack的Firebase无法正常工作 – 无法读取未定义的属性“navigator”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我收到以下错误

/Users/.../express/server/bundle.js:296
        License: https://www.firebase.com/terms/terms-of-service.html */(function(){var h,n=this;function p(a){return void 0!==a;}function aa(){}function ba(a){a.wb=function(){return a.wf?a.wf:a.wf=new a();};}function ca(a){var b=typeof a==="undefined"?"undefined":_typeof(a);if("object"==b){if(a){if(a instanceof Array)return "array";if(a instanceof Object)return b;var c=Object.prototype.toString.call(a);if("[object Window]"==c)return "object";if("[object Array]"==c||"number"==typeof a.length&&"undefined"!=typeof a.splice&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("splice"))return "array";if("[object Function]"==c||"undefined"!=typeof a.call&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("call"))return "function";}else return "null";}else if("function"==b&&"undefined"==typeof a.call)return "object";return b;}function da(a){return "array"==ca(a);}function ea(a){var b=ca(a);r

TypeError: Cannot read property 'navigator' of undefined
    at /Users/.../server/bundle.js:296:4904
    at Object.

这是我的webpack配置:

var webpack = require('webpack');

module.exports = {
  entry: './server/entry.js',output: {
    filename: './server/bundle.js'
  },target: "node",devtool: 'source-map',resolve: {
    extensions: ['','.webpack.js','.js','.json'],modulesDirectories: [
      'node_modules'
    ]
  },module: {
    loaders: [
      { 
        test: /\.json$/,exclude: '/node_modules/',loader: "json-loader" 
      },{ 
        test: /\.js$/,loader: 'babel-loader',query: {
          presets: ['es2015']
        }
      }
    ]
  }
};

运行“node app.js”时会打印出此错误.我正在尝试使用Node和Express for Rest API运行此代码,因此正在Node.js而不是浏览器中加载.

最佳答案
您遇到的问题是因为webpack默认使用firebase package.json中指定的Firebase的“浏览器”版本,而不是“main”版本(node.js的版本). “浏览器”版本不起作用.

根据webpack configuration docs,看起来您可以通过以下方式覆盖其排序:

"resolve": {
    "packageMains": [ "main","webpack","browser","web","browserify",["jam","main"]]
}

(这是未经测试的;我只是采用默认值并先移动“main”)

原文链接:https://www.f2er.com/js/428978.html

猜你在找的JavaScript相关文章