I followed this tutorial for creating server side rendered app. The error occurs when I try to serve the app using npm run serve:ssr
.
The error I get is:
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)
Before this I was receiving an error window is not defined
so I added the below code in server.ts
as mentioned in 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;
When I build ssr app using npm run build:ssr
, I receive warnings shown below
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
Also when I serve(d) app using npm run serve:ssr
while I receive these warnings when I used [email protected]
I received error reference: self is not defined
after updating to [email protected]
I receive error
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)
I remove these warnings and errors by updating webpack.server.config.js
by adding lines below
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();
}],
...
}
I also found out this stackoverflow question related to this error but I don't use performance module so solution is not applicable to me.
How can I solve this IDBIndex
error ? Please help
A detailed explanation on why this happens has been commented here. They provided a workaround but a fix will also come.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With