简体   繁体   English

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

[英]Firebase with Node and Webpack not working - Cannot read property 'navigator' of undefined

I'm getting the following error: 我收到以下错误:

/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.<anonymous> (/Users/.../server/bundle.js:296:143270)
    at __webpack_require__ (/Users/.../server/bundle.js:20:30)
    at Object._typeof (/Users/.../server/bundle.js:239:18)
    at __webpack_require__ (/Users/.../server/bundle.js:20:30)
    at Object.i (/Users/.../server/bundle.js:52:14)
    at __webpack_require__ (/Users/.../server/bundle.js:20:30)
    at /Users/.../server/bundle.js:40:18
    at Object.<anonymous> (/Users/.../server/bundle.js:43:10)
    at Module._compile (module.js:435:26)

This is my webpack config: 这是我的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$/, 
        exclude: '/node_modules/', 
        loader: 'babel-loader',
        query: {
          presets: ['es2015']
        }
      }
    ]
  }
};

This error prints out when I run "node app.js". 运行“node app.js”时会打印出此错误。 I'm trying to run this code using Node and Express for Rest API, so is being loaded within Node.js and not the browser. 我正在尝试使用Node和Express for Rest API运行此代码,因此正在Node.js而不是浏览器中加载。

The issue you're hitting is because webpack will by default use the "browser" version of Firebase as specified in the firebase package.json, rather than the "main" version (which is the one for node.js). 您遇到的问题是因为webpack默认使用firebase package.json中指定的Firebase的“浏览器”版本,而不是“main”版本(node.js的版本)。 The "browser" version won't work. “浏览器”版本不起作用。

According to the webpack configuration docs it looks like you may be able to override its ordering with something like: 根据webpack配置文档 ,您似乎可以使用以下内容覆盖其排序:

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

(this is untested; I just took the defaults and moved "main" first) (这是未经测试的;我只是采用了默认值并首先移动了“main”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:无法读取未定义节点 Js firebase 函数的属性“修剪” - TypeError: Cannot read property 'trim' of undefined Node Js firebase functions npx webpack - 无法读取undefined的属性&#39;minify&#39; - npx webpack - Cannot read property 'minify' of undefined Webpack:TypeError:无法读取未定义的属性“属性” - Webpack: TypeError: Cannot read property 'properties' of undefined 无法读取未定义的属性“ engine”-Webpack React - Cannot read property 'engine' of undefined - Webpack React React-Native Navigator:无法读取未定义的属性“ push” - React-Native Navigator: Cannot read property 'push' of undefined 在 Node.js 应用程序中使用 Webpack 时出现类型错误“无法读取未定义的属性 'jquery'” - TypeError “Cannot read property 'jquery' of undefined” while using Webpack in Node.js app Firebase函数无法读取未定义的属性“ val” - Firebase functions Cannot read property 'val' of undefined Firebase TypeError:无法读取未定义的属性“ ac” - Firebase TypeError: Cannot read property 'ac' of undefined Firebase TypeError:无法读取未定义的属性“val” - Firebase TypeError: Cannot read property 'val' of undefined Firebase函数:无法读取未定义的属性“ val” - Firebase Functions: Cannot read property 'val' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM