2016-05-23 49 views
3

我目前正在構建一個應用程序,並試圖測試使用Express創建的生產服務器環境。當通過webpack-dev-server提供服務時,該應用程序工作正常,但是當我的Express server.js被webpack捆綁並且node server.bundle.js正在運行時,我得到有關Firebase存儲的以下錯誤。Firebase存儲無法在Express服務器環境中工作

/Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js:533 
    var storage = _firebaseConfig2.default.storage(); 
             ^

TypeError: _firebaseConfig2.default.storage is not a function 

節點最終只是切換到運行我的開發環境。

下面是我的package.json包含我的依賴關係和npm腳本後面跟着我的終端日誌。

所有谷歌/ stackoverflow搜索我做了'_firebaseConfig2.default.storage不是一個函數'幾乎沒有什麼。

的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" 
    } 
} 

日誌

=> NODE_ENV=production npm start 

> [email protected] start /Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp 
> if-env NODE_ENV=production && npm run start:prod || npm run start:dev 


> [email protected] start:prod /Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp 
> npm run build && node server.bundle.js 


> [email protected] build /Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp 
> npm run build:client && npm run build:server 


> [email protected] 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 

> [email protected] 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! [email protected] start:prod: `npm run build && node server.bundle.js` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] 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 

> [email protected] 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 

回答

5

火力地堡貯存開發這裏:

火力地堡存儲是目前唯一的瀏覽器JS。由於​​已經提供了許多高質量的客戶端庫,我們不希望重新實現另一個 - 我們建議使用GCloud-Node庫來進行這種類型的開發。您可以將其與現有的存儲桶以及典型的Firebase Server開發設置說明一起使用。

+0

謝謝Mike。 然後給你一個問題。由於我在我的主bundle.js中使用瀏覽器版本,其中包含我所有的反應應用程序JS,我認爲它會工作。難道是因爲我用Express渲染React代碼服務器端,它不再被視爲瀏覽器JS?我對Webpack,Express,React甚至Firebase都很陌生(剛剛在上週開始)。 – CSSDevMonkey

+1

這很令人困惑,NodeJS API應該像數據庫API一樣匹配瀏覽器API。 – jujule

+1

我同意不同的API有點混淆,我們正在研究使它們在將來更加相似的選項。 –

1

同意,這似乎違背了Firebase的全部目的。一方面官方的doco在某些地方說「...對於Firebase Node.JS的某些功能是必需的......」(或類似的),但在這種情況下,我們不能使用Node.JS.

相關問題