我遵循了this教程来创建服务器端渲染的应用程序。当我尝试使用npm run serve:ssr
为应用提供服务时,会发生错误。
我得到的错误是:
proxyRequestMethods(Index, '_index', IDBIndex, [
^
ReferenceError: IDBIndex is not defined
at Module.<anonymous> (C:\Users\eg\dist\server.js:343794:38)
at __webpack_require__ (C:\Users\eg\dist\server.js:30:30)
at Module.<anonymous> (C:\Users\eg\dist\server.js:342436:61)
at __webpack_require__ (C:\Users\eg\dist\server.js:30:30)
at Module.<anonymous> (C:\Users\eg\dist\server.js:341227:81)
at __webpack_require__ (C:\Users\eg\dist\server.js:30:30)
at Module.<anonymous> (C:\Users\eg\dist\server.js:332069:79)
at __webpack_require__ (C:\Users\eg\dist\server.js:30:30)
at Object.firebase (C:\Users\eg\dist\server.js:189647:18)
at __webpack_require__ (C:\Users\eg\dist\server.js:137349:30)
在此之前,我收到错误window is not defined
,所以我在server.ts
中添加了以下代码,如this comment
const domino = require('domino');
const fs = require('fs');
const path = require('path');
const template = fs.readFileSync(path.join(__dirname, '.', 'dist', 'index.html')).toString();
const win = domino.createWindow(template);
global['window'] = win;
global['document'] = win.document;
当我使用npm run build:ssr
构建ssr应用程序时,收到如下所示的警告
WARNING in ./node_modules/@angular/fire/firestore/firestore.js 23:21-32
"export 'SDK_VERSION' was not found in 'firebase/app'
@ ./node_modules/@angular/fire/firestore/public_api.js
@ ./node_modules/@angular/fire/firestore/index.js
@ ./dist/server/main.js
@ ./server.ts
WARNING in ./node_modules/@angular/fire/firestore/firestore.js 24:21-32
"export 'SDK_VERSION' was not found in 'firebase/app'
@ ./node_modules/@angular/fire/firestore/public_api.js
@ ./node_modules/@angular/fire/firestore/index.js
@ ./dist/server/main.js
@ ./server.ts
当我使用npm run serve:ssr
服务{d}应用程序时,当我使用firebase@5.x.x
收到这些警告时,在更新为reference: self is not defined
后收到错误firebase@6.0.2
时,我收到错误< / p>
var major = parseInt(firebase_app__WEBPACK_IMPORTED_MODULE_6__["SDK_VERSION"].split('.')[0]);
TypeError: Cannot read property 'split' of undefined
at Module.<anonymous> (C:\Users\eg\dist\server.js:279474:79)
at __webpack_require__ (C:\Users\eg\dist\server.js:30:30)
at Module.<anonymous> (C:\Users\eg\dist\server.js:279385:68)
at __webpack_require__ (C:\Users\eg\dist\server.js:30:30)
at Module.<anonymous> (C:\Users\eg\dist\server.js:279341:69)
at __webpack_require__ (C:\Users\eg\dist\server.js:30:30)
at Object.@angular/fire/firestore (C:\Users\eg\dist\server.js:189255:18)
at __webpack_require__ (C:\Users\eg\dist\server.js:137353:30)
at Object../src/app/services/global-manager.service.ts (C:\Users\eg\dist\server.js:186535:19)
at __webpack_require__ (C:\Users\eg\dist\server.js:137353:30)
我通过在下面添加以下行来更新webpack.server.config.js
,以消除这些警告和错误
const regex = /firebase\/(app|firestore)/;
module.exports={
externals: [/node_modules/, function(context, request, callback) {
// exclude firebase products from being bundled, so they will be loaded using require() at runtime.
if(regex.test(request)) {
return callback(null, 'commonjs ' + request);
}
callback();
}],
...
}
我还发现了 this与该错误有关的stackoverflow问题,但是我没有使用性能模块,因此该解决方案不适用于我。
如何解决此IDBIndex
错误?请帮助