Firebase存储无法在Express服务器环境中使用 [英] Firebase Storage Not working in Express Server Environment
问题描述
我目前正在构建一个应用程序,并试图测试使用Express创建的生产服务器环境。当通过webpack-dev-server提供服务时,应用程序工作正常,但是当我的Express server.js
被webpack捆绑,并且 node server.bundle。 js
正在运行我得到了有关Firebase存储的以下错误:
/ Users / palcisto / Sites / sandbox / MTBparks / MTBparksMemberApp / server.bundle.js:533
var storage = _firebaseConfig2.default.storage();
^
TypeError:_firebaseConfig2.default.storage不是函数
节点最终只是切换到运行我的开发环境。
下面是我的 package.json
,其中包含我的依赖和npm脚本,后面跟着终端的日志。 p>
所有google / stackoverflow搜索我做了'_firebaseConfig2.default.storage不是一个函数'几乎没有任何东西。
Package.json
{
pre>
name:mtbparks-member -app,
version:0.1.0,
main:index.html,
scripts:{
start: if-env NODE_ENV = production&& npm run start:prod || npm run start:dev,
start:dev:webpack-dev-server --inline --content-base build / - 历史-API的回退和放大器;&安培; postcss --use autoprefixer -d打造的src / Styles.css中
开始:正式版: 故宫运行构建和放大器;&安培;节点server.bundle.js ,
build:client:webpack&& postcss --use autoprefixer -d build src / styles.css,
build:server:webpack --config webpack。 server.config.js,
build:np m run build:client&& npm run build:server,
test:echo \错误:未指定测试&&退出1
,
license:ISC,
devDependencies:{
autoprefixer:^ 6.3.6,
babel-core:^ 6.8.0,
babel-loader:^ 6.2.4,
babel-polyfill:^ 6.9.0,
babel-preset-es2015:^ 6.6.0,
babel-preset-react:^ 6.5.0,
eslint:^ 2.9.0,
eslint-loader:^ 1.3.0,
eslint-plugin-react:^ 5.1.1,
http-server:^ 0.9.0 ,
postcss-cli:^ 2.5.2,
postcss-loader:^ 0.9.1,
webpack:^ 1.13.0 ,
webpack-dev-server:^ 1.14.1
},
dependencies:{
compression:^ 1.6.2,
express:^ 4.13.4,
firebase:3.0.2,
foundation-sites:^ 6.2.1,
if-env:^ 1.0.0,
re-base:^ 1.5.1,
react:^ 15.0.2,
反应-dom:^ 15.0.2,
react-router:^ 2.4.0
}
}
记录
=> NODE_ENV = production npm start
$ Firebase存储设备在这里:
> mtbparks-member-app@0.1.0 start / Users / palcisto / Sites / sandbox / MTBparks / MTBparksMemberApp
> if-env NODE_ENV = production&& npm run start:prod || npm run start:dev
> mtbparks-member-app@0.1.0 start:prod / Users / palcisto / Sites / sandbox / MTBparks / MTBparksMemberApp
> npm run build&&节点server.bundle.js
> mtbparks-member-app@0.1.0 build / Users / palcisto / Sites / sandbox / MTBparks / MTBparksMemberApp
> npm run build:client&& npm run build:server
> mtbparks-member-app@0.1.0 build:client / Users / palcisto / Sites / sandbox / MTBparks / MTBparksMemberApp
> webpack&& postcss --use autoprefixer -d打造的src / styles.css的
哈希:cf9ca8bbc1315fc1c9db
版:的WebPack 1.13.0
时间:14624ms
资产大小的块组块名称
bundle.js 855 kB 0 [emit] main
bundle.js.map 4.59 MB 0 [emit] main
[0] multi main 40 bytes {0} [built]
+ 538隐藏模块
> mtbparks-member-app@0.1.0 build:server / Users / palcisto / Sites / sandbox / MTBparks / MTBparksMemberApp
>的WebPack --config webpack.server.config.js
哈希:4561926734ef8e1e5a47
版:的WebPack 1.13.0
时间:973ms
资产大小的块组块名
server.bundle.js 27.6 kB 0 [emit] main
[0] multi main 40 bytes {0} [built]
+ 17 hidden modules
/ Users / palcisto / Sites / sandbox / MTBparks / MTBparksMemberApp / server.bundle.js:533
var storage = _firebaseConfig2.default.storage();
^
TypeError:_firebaseConfig2.default.storage不是Object.defineProperty.value(/ Users / palcisto / Sites / sandbox / MTBparks / MTBparksMemberApp / server中的函数
。 bundle.js:533:41)
。在__webpack_require__(/Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js:20:30)
。在Object.defineProperty.value(/
at __webpack_require__(/Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js:20:Users / palcisto / Sites / sandbox / MTBparks / MTBparksMemberApp / server.bundle.js:179:14) 30)
在Object。< anonymous> (/Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js:83:16)
在Object。< anonymous> (/Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js:121:31)
at __webpack_require__(/Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js: 20:30)在对象
< anonymous> (/Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js:48:19)
at __webpack_require__(/Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js: 20:30)
at /Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js:40:18
npm ERR!达尔文14.5.0
npm ERR! argv/Users/palcisto/.nvm/versions/node/v5.11.1/bin/node/Users/palcisto/.nvm/versions/node/v5.11.1/bin/npmrunstart:prod
npm ERR!节点v5.11.1
npm ERR! npm v3.8.6
npm ERR!代码ELIFECYCLE
npm ERR! mtbparks-member-app@0.1.0 start:prod:`npm run build&&节点server.bundle.js`
npm ERR!退出状态1
npm ERR!
npm ERR!在mtbparks-member-app@0.1.0启动失败:prod脚本'npm run build&&节点server.bundle.js'。
npm ERR!确保你已经安装了最新版本的node.js和npm。
npm ERR!如果你这样做,这可能是mtbparks-member-app软件包的问题,
npm ERR!而不是npm本身。
npm ERR!告诉作者,你的系统失败了:
npm ERR! npm run build&&节点server.bundle.js
npm ERR!您可以通过以下方式获得有关如何为此项目打开问题的信息:
npm ERR! npm错误mtbparks-member-app
npm ERR!或者,如果不可用,您可以通过以下方式获取他们的信息:
npm ERR! npm所有者ls mtbparks-member-app
npm ERR!上面可能还有额外的日志输出。
npm ERR!请包括以下任何支持请求的文件:
npm ERR! /Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/npm-debug.log
> mtbparks-member-app@0.1.0 start:dev / Users / palcisto / Sites / sandbox / MTBparks / MTBparksMemberApp
> webpack-dev-server --inline --content-base build / --history-api-fallback&& postcss --use autoprefixer -d构建src / styles.css
http:// localhost:8080 /
webpack结果来自/
内容来自/ Users / palcisto / Sites / sandbox / MTBparks / MTBparksMemberApp / build
404s将会回退到/index.html
Hash:e38d4972b9458e39b46c
版本:webpack 1.13.0
时间:16461ms
资产大小块块名称
bundle.js 928 kB 0 [已发行] main
bundle.js.map 5.17 MB 0 [已发行] main
Firebase存储目前是浏览器JS只。由于 Google云端存储已经提供了许多高质量的客户端库,因此我们不希望重新实现另一个 - 我们建议您使用 GCloud-Node 库进行此类开发。您可以将其与现有的存储分区和典型的 Firebase Server 开发设置说明一起使用。 / p>
I am currently building an app and am trying to test the production server environment I created using Express. The application works fine when served via webpack-dev-server, but when my Express
server.js
is bundled by webpack, andnode server.bundle.js
is run I get the following error regarding Firebase storage./Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js:533 var storage = _firebaseConfig2.default.storage(); ^ TypeError: _firebaseConfig2.default.storage is not a function
Node ends up just switching to running my dev environment.
Below are my
package.json
containing my dependencies and npm scripts followed by the log from my terminal.All google/stackoverflow searching I did on '_firebaseConfig2.default.storage is not a function' turned up just about nothing.
Package.json
{ "name": "mtbparks-member-app", "version": "0.1.0", "main": "index.html", "scripts": { "start": "if-env NODE_ENV=production && npm run start:prod || npm run start:dev", "start:dev": "webpack-dev-server --inline --content-base build/ --history-api-fallback && postcss --use autoprefixer -d build src/styles.css", "start:prod": "npm run build && node server.bundle.js", "build:client": "webpack && postcss --use autoprefixer -d build src/styles.css", "build:server": "webpack --config webpack.server.config.js", "build": "npm run build:client && npm run build:server", "test": "echo \"Error: no test specified\" && exit 1" }, "license": "ISC", "devDependencies": { "autoprefixer": "^6.3.6", "babel-core": "^6.8.0", "babel-loader": "^6.2.4", "babel-polyfill": "^6.9.0", "babel-preset-es2015": "^6.6.0", "babel-preset-react": "^6.5.0", "eslint": "^2.9.0", "eslint-loader": "^1.3.0", "eslint-plugin-react": "^5.1.1", "http-server": "^0.9.0", "postcss-cli": "^2.5.2", "postcss-loader": "^0.9.1", "webpack": "^1.13.0", "webpack-dev-server": "^1.14.1" }, "dependencies": { "compression": "^1.6.2", "express": "^4.13.4", "firebase": "3.0.2", "foundation-sites": "^6.2.1", "if-env": "^1.0.0", "re-base": "^1.5.1", "react": "^15.0.2", "react-dom": "^15.0.2", "react-router": "^2.4.0" } }
Logs
=> NODE_ENV=production npm start > mtbparks-member-app@0.1.0 start /Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp > if-env NODE_ENV=production && npm run start:prod || npm run start:dev > mtbparks-member-app@0.1.0 start:prod /Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp > npm run build && node server.bundle.js > mtbparks-member-app@0.1.0 build /Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp > npm run build:client && npm run build:server > mtbparks-member-app@0.1.0 build:client /Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp > webpack && postcss --use autoprefixer -d build src/styles.css Hash: cf9ca8bbc1315fc1c9db Version: webpack 1.13.0 Time: 14624ms Asset Size Chunks Chunk Names bundle.js 855 kB 0 [emitted] main bundle.js.map 4.59 MB 0 [emitted] main [0] multi main 40 bytes {0} [built] + 538 hidden modules > mtbparks-member-app@0.1.0 build:server /Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp > webpack --config webpack.server.config.js Hash: 4561926734ef8e1e5a47 Version: webpack 1.13.0 Time: 973ms Asset Size Chunks Chunk Names server.bundle.js 27.6 kB 0 [emitted] main [0] multi main 40 bytes {0} [built] + 17 hidden modules /Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js:533 var storage = _firebaseConfig2.default.storage(); ^ TypeError: _firebaseConfig2.default.storage is not a function at Object.defineProperty.value (/Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js:533:41) at __webpack_require__ (/Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js:20:30) at Object.defineProperty.value (/Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js:179:14) at __webpack_require__ (/Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js:20:30) at Object.<anonymous> (/Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js:83:16) at Object.<anonymous> (/Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js:121:31) at __webpack_require__ (/Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js:20:30) at Object.<anonymous> (/Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js:48:19) at __webpack_require__ (/Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js:20:30) at /Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js:40:18 npm ERR! Darwin 14.5.0 npm ERR! argv "/Users/palcisto/.nvm/versions/node/v5.11.1/bin/node" "/Users/palcisto/.nvm/versions/node/v5.11.1/bin/npm" "run" "start:prod" npm ERR! node v5.11.1 npm ERR! npm v3.8.6 npm ERR! code ELIFECYCLE npm ERR! mtbparks-member-app@0.1.0 start:prod: `npm run build && node server.bundle.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the mtbparks-member-app@0.1.0 start:prod script 'npm run build && node server.bundle.js'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the mtbparks-member-app package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! npm run build && node server.bundle.js npm ERR! You can get information on how to open an issue for this project with: npm ERR! npm bugs mtbparks-member-app npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm owner ls mtbparks-member-app npm ERR! There is likely additional logging output above. npm ERR! Please include the following file with any support request: npm ERR! /Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/npm-debug.log > mtbparks-member-app@0.1.0 start:dev /Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp > webpack-dev-server --inline --content-base build/ --history-api-fallback && postcss --use autoprefixer -d build src/styles.css http://localhost:8080/ webpack result is served from / content is served from /Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/build 404s will fallback to /index.html Hash: e38d4972b9458e39b46c Version: webpack 1.13.0 Time: 16461ms Asset Size Chunks Chunk Names bundle.js 928 kB 0 [emitted] main bundle.js.map 5.17 MB 0 [emitted] main
解决方案Firebase Storage dev here:
Firebase Storage is currently browser JS only. Since Google Cloud Storage already provides a number of high quality client libraries, we didn't want to reimplement another--we recommend using the GCloud-Node library for this type of development. You can use this with your existing storage bucket and the typical Firebase Server development setup instructions.
这篇关于Firebase存储无法在Express服务器环境中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!