Closed mazlano27 closed 2 years ago
I have been trying to find a solution for this for about 5 days now. I tried downgrading to 13.0.3 but still, get the error.
If I remove angular/fire for authentication it is resolved. Extremely frustrating.
I have been trying to find a solution for this for about 5 days now. I tried downgrading to 13.0.3 but still, get the error.
If I remove angular/fire for authentication it is resolved. Extremely frustrating.
Please check your package-lock.json if your angular version is the version you downgraded to? I sometimes find that the package.json version is different from package-lock.json version and this causes the issue.
The only solution i found was to manually uninstall all the angular packages (npm uninstall @angular/core.....) and then manually installing them again with the desired version (npm install --save @angular/core@13.0.3 ......)
@mazlano27 you just saved my life on this. You were right. lock file had 3.1. Removed and manually added back 3.0.x and now dev:ssr is working!
I have been trying to find a solution for this for about 5 days now. I tried downgrading to 13.0.3 but still, get the error. If I remove angular/fire for authentication it is resolved. Extremely frustrating.
Please check your package-lock.json if your angular version is the version you downgraded to? I sometimes find that the package.json version is different from package-lock.json version and this causes the issue.
The only solution i found was to manually uninstall all the angular packages (npm uninstall @angular/core.....) and then manually installing them again with the desired version (npm install --save @angular/core@13.0.3 ......)
I've been stuck on this for days. That saved my ass. Thanks
I'm running into this error too when running Universal. Any solutions?
It seems to be firebase related. See also this issue. I don't understand how upgrading from 13.0 to 13.1 is causing this tho, nor how I could apply the suggested workaround in an Angular app.
This is my diff after I ran nx migrate latest
and started running into this issue: https://gist.github.com/Burgov/50682abd0f12e8c13fd51bf013616f9d
I ran into this issue when upgrading from 12 to 13.1.
My project was not using a custom webpack file, but creating a webpack config file as documented (from 2018...) here solved my problem: https://github.com/angular/angularfire/blob/master/docs/universal/getting-started.md#3-add-a-webpack-config-for-the-express-server
Thank you for sharing. I tried to create the webpack config file but realised it was for SSR (and not pre-rendering). I tried it still and it does not seem to work for pre-rendering.
I tried to add the firebase packages as external dependencies in the angular.json file too - that didn't help either :/
@kgajera thank you for your insight - based on some experimentation, I managed to find the fix! :)
Solution: Create a custom webpack file which excludes firebase from the server bundle.
Steps:
module.exports = {
externals: [
/^firebase/
]
}
"server": {
"builder": "@angular-builders/custom-webpack:server",
"options": {
"customWebpackConfig": {
"path": "./custom-webpack.config.js",
"replaceDuplicatePlugins": true
},
...
},
},
References:
Why is this suddenly necessary? Everything works fine with NG 13.0. I don't really like having to add a custom webpack config
This sounds like something very much not an issue with Angular Universal. Can anyone point to something specific in Universal that shows the problem? If it's just a problem with Angular Fire, solved using the workaround they published, then we can either close this, or repurpose this to add docs for how to handle this edge case in the README.
This sounds like something very much not an issue with Angular Universal. Can anyone point to something specific in Universal that shows the problem? If it's just a problem with Angular Fire, solved using the workaround they published, then we can either close this, or repurpose this to add docs for how to handle this edge case in the README.
@CaerusKaru I'm not sure where this issue arises. It started after the 13.1 update - and I'm unable to point to something specific in Universal that shows the problem. Rolling back to 13.0 resolved the issue.
I think it's useful to document (as an edge case) how we might be able to exclude certain libraries from the universal build pipeline incase these libraries cause errors in the server side node environment?
Has anyone found a solution? I'am stuck at it and I really don't want to add custom webpack config
Hello all seems that I'm facing the same problem, and has I have read the most direct solution is to downgrade Angular do 13.03 . My question is, I need to downgrade all Angular libs to 13.03 ? there are any easy way todo this downgrade the right way ?
Hello all seems that I'm facing the same problem, and has I have read the most direct solution is to downgrade Angular do 13.03 . My question is, I need to downgrade all Angular libs to 13.03 ? there are any easy way todo this downgrade the right way ?
I was able to temporarily use mazlano27's solution. It's working and I don't need to downgrade but keep in mind that you would have to reverse this 'fix' in the future.
I also have this problem for 2 days. I just found this issue and saw that it's not just me. Has anyone had any progress in solving this problem?
Angular CLI: 13.1.2
Node: 16.13.1
Package Manager: npm 8.1.2
OS: linux x64
Angular: 13.1.1
... animations, cdk, common, compiler, compiler-cli, core, forms
... material, material-moment-adapter, platform-browser
... platform-browser-dynamic, platform-server, router
... youtube-player
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1301.2
@angular-devkit/build-angular 13.1.2
@angular-devkit/core 13.1.2
@angular-devkit/schematics 13.1.2
@angular/cli 13.1.2
@angular/fire 7.2.0
@nguniversal/builders 13.0.1
@nguniversal/express-engine 13.0.1
@schematics/angular 13.1.2
rxjs 7.5.1
typescript 4.5.4
I created this empty project to simulate the problem and show that it's not an error in the code I made. https://github.com/miguelsmuller/teste-project
I just followed the following steps:
ng new teste-project
ng add @angular/material
ng add @ngrx/store
ng add @ngrx/effects
ng add @nguniversal/express-engine
ng add @angular/fire
each command above is a commit from that test project
the last command (ng add @angular/fire) returned as shown in the image below. The informed parameters are also shown in the image.
and finally the error that is displayed when I run the command npm run build:ssr && npm run serve:ssr
- image below in the right column. You can also see in this image on the left that when I run npm run start
as csr no error is displayed.
Angular CLI: 13.1.2
Node: 16.13.1
Package Manager: npm 8.1.2
OS: linux x64
Angular: 13.1.1
... animations, cdk, common, compiler, compiler-cli, core, forms
... material, platform-browser, platform-browser-dynamic
... platform-server, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1301.2
@angular-devkit/build-angular 13.1.2
@angular-devkit/core 13.1.2
@angular-devkit/schematics 13.1.2
@angular/cli 13.1.2
@angular/fire 7.2.0
@nguniversal/builders 13.0.1
@nguniversal/express-engine 13.0.1
@schematics/angular 13.1.2
rxjs 7.4.0
typescript 4.5.4
Downgrading (from 17/16) to Node ^14 helped me.
I have tried downgrading to 13.0.3 but it still throws the same error. Any solutions yet?
I am facing same issue
ReferenceError: IDBIndex is not defined
after I upgrade the Angular version from 12.0.1 to 13.1.3.
after I use 'node dist/localmasters/server/main.js' I get below error.
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 13.1.4
Node: 16.13.2
Package Manager: npm 8.1.2
OS: darwin arm64
Angular: 13.1.3
... animations, cdk, common, compiler, compiler-cli, core, forms
... language-service, material, material-moment-adapter
... platform-browser, platform-browser-dynamic, platform-server
... router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1301.4
@angular-devkit/build-angular 13.1.4
@angular-devkit/core 13.1.4
@angular-devkit/schematics 13.1.4
@angular/cli 13.1.4
@angular/fire 6.1.5
@nguniversal/builders 12.1.0
@nguniversal/express-engine 12.1.0
@schematics/angular 13.1.4
rxjs 7.5.2
typescript 4.5.5
Downgrading to 13.0.3 does helped to stay in Angular 13.
package.json
"dependencies": {
"@angular/animations": "^13.0.3",
"@angular/cdk": "^13.0.3",
"@angular/common": "13.0.3",
"@angular/compiler": "13.0.3",
"@angular/core": "13.0.3",
"@angular/fire": "^6.1.4",
"@angular/forms": "13.0.3",
"@angular/material": "13.0.3",
"@angular/material-moment-adapter": "13.0.3",
"@angular/platform-browser": "13.0.3",
"@angular/platform-browser-dynamic": "13.0.3",
"@angular/platform-server": "13.0.3",
"@angular/router": "13.0.3",
"@nguniversal/express-engine": "^12.0.0",
"@types/jspdf": "^1.3.3",
"@types/stripe": "^7.13.25",
"animate.css": "^4.1.1",
"aos": "^2.3.4",
"apexcharts": "^3.26.1",
"bootstrap": "^5.1.3",
"crypto-js": "4.0.0",
"data-uri-to-buffer": "^4.0.0",
"domino": "^2.1.6",
"express": "^4.15.2",
"fetch-blob": "^3.1.4",
"firebase": "^8.10.0",
"formdata-polyfill": "^4.0.10",
"highlight.js": "10.7.2",
"lodash-es": "4.17.21",
"moment": "^2.29.1",
"ng-apexcharts": "^1.5.9",
"ng-starrating": "^1.0.20",
"ng-stripe-checkout": "^1.0.4",
"ng-wistia-components": "0.0.2",
"ngx-device-detector": "^2.0.8",
"ngx-infinite-scroll": "^10.0.1",
"ngx-mat-select-search": "^3.2.0",
"ngx-moment": "^5.0.0",
"node-fetch": "^3.2.0",
"perfect-scrollbar": "1.5.0",
"quill": "1.3.7",
"rrule": "2.6.8",
"rxjs": "7.5.2",
"stripe": "^8.116.0",
"stripe-angular": "^1.2.1",
"tslib": "2.2.0",
"yum": "^0.1.1",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "13.0.3",
"@angular/cli": "^13.0.3",
"@angular/compiler-cli": "13.0.3",
"@angular/language-service": "13.0.3",
"@nguniversal/builders": "^12.0.0",
"@ngx-builders/analyze": "^2.3.0",
"@types/crypto-js": "4.0.1",
"@types/express": "^4.17.0",
"@types/highlight.js": "9.12.4",
"@types/jasmine": "3.6.10",
"@types/jasminewd2": "2.0.8",
"@types/lodash-es": "4.17.4",
"@types/node": "15.0.1",
"bufferutil": "^4.0.3",
"codelyzer": "6.0.2",
"jasmine-core": "3.7.1",
"jasmine-spec-reporter": "7.0.0",
"karma": "6.3.2",
"karma-chrome-launcher": "3.1.0",
"karma-coverage-istanbul-reporter": "3.0.3",
"karma-jasmine": "4.0.1",
"karma-jasmine-html-reporter": "1.5.4",
"ngx-owl-carousel-o": "^6.0.0",
"protractor": "7.0.0",
"tailwindcss": "2.1.2",
"ts-node": "9.1.1",
"tslint": "6.1.2",
"typescript": "~4.4.0",
"utf-8-validate": "^5.0.5",
"ws": "^8.2.2",
"xhr2": "^0.2.1"
}
I have tried downgrading to 13.0.3 but it still throws the same error. Any solutions yet?
Delete these
package-lock.json
node_modules
Update version manually for angular and material. Try matching this package.json I did tried downgrade to 13.0.3 and it worked.
package.json
"dependencies": {
"@angular/animations": "^13.0.3",
"@angular/cdk": "^13.0.3",
"@angular/common": "13.0.3",
"@angular/compiler": "13.0.3",
"@angular/core": "13.0.3",
"@angular/fire": "^6.1.4",
"@angular/forms": "13.0.3",
"@angular/material": "13.0.3",
"@angular/material-moment-adapter": "13.0.3",
"@angular/platform-browser": "13.0.3",
"@angular/platform-browser-dynamic": "13.0.3",
"@angular/platform-server": "13.0.3",
"@angular/router": "13.0.3",
"@nguniversal/express-engine": "^12.0.0",
},
"devDependencies": {
"@angular-devkit/build-angular": "13.0.3",
"@angular/cli": "^13.0.3",
"@angular/compiler-cli": "13.0.3",
"@angular/language-service": "13.0.3",
......
And run npm install
It should work for version 13.0.3
@kgajera thank you for your insight - based on some experimentation, I managed to find the fix! :)
Solution: Create a custom webpack file which excludes firebase from the server bundle.
Steps:
- Install @angular-builders/custom-webpack as a dev dependency
- Create a file "custom-webpack.config.js" in the project root and add the following:
module.exports = { externals: [ /^firebase/ ] }
- Update angular.json to incorporate this custom webpack config into the build process
"server": { "builder": "@angular-builders/custom-webpack:server", "options": { "customWebpackConfig": { "path": "./custom-webpack.config.js", "replaceDuplicatePlugins": true }, ... }, },
- Done!
References:
- https://alligator.io/angular/Custom-webpack-config/
- https://github.com/angular/angularfire/blob/master/docs/universal/getting-started.md#3-add-a-webpack-config-for-the-express-server
- WebpackError: ReferenceError: IDBIndex is not defined while building with Gatsby.JS (ver #2.15.21) firebase/firebase-js-sdk#2222 (comment)
I am getting Error: No template for dependency: PureExpressionDependency
errors after following custom webpack configuration.
any idea how to fix this.
then @Santoshah
I believe that it may be some incompatibility between the modules and even if you have removed the firebase from the webpack it is necessary... so it is giving an error...
taking firebase completely out of the bundle I don't think it's the ideal solution.
must have some firebase method that angular universal, for being ssr, is not able to execute.
the ideal would be someone from the core of one of the modules to at least open our eyes to what could be.
AngularFire maintainer here, the root cause appears to be Firebase JS SDK's usage of the idb
library. The version of the library that it uses doesn't have exports in its package.json and expects CJS to be loaded in Node.js. In Angular 13.1+ (unsure exactly which minor the change was introduced) that means unguarded calls to IndexDB are present in your server bundle, since it's now bundling ESM, and causing runtime exceptions on load...
AngularFire maintainer here, the root cause appears to be Firebase JS SDK's usage of the
idb
library. The version of the library that it uses doesn't have exports in its package.json and expects CJS to be loaded in Node.js. In Angular 13.1+ (unsure exactly which minor the change was introduced) that means unguarded calls to IndexDB are present in your server bundle, since it's now bundling ESM, and causing runtime exceptions on load...
Are there any plans to correct this?
IMO this can be closed now that root cause has been identified as Firebase JS SDK, move conversation there.
@jmarlow4 I opened an issue on that repo, I can only say that the team has been made aware. There are plans that would address the root cause at some point, hoping we can prioritize at least a short term fix.
@kgajera thank you for your insight - based on some experimentation, I managed to find the fix! :)
Solution: Create a custom webpack file which excludes firebase from the server bundle.
Steps:
- Install @angular-builders/custom-webpack as a dev dependency
- Create a file "custom-webpack.config.js" in the project root and add the following:
module.exports = { externals: [ /^firebase/ ] }
- Update angular.json to incorporate this custom webpack config into the build process
"server": { "builder": "@angular-builders/custom-webpack:server", "options": { "customWebpackConfig": { "path": "./custom-webpack.config.js", "replaceDuplicatePlugins": true }, ... }, },
- Done!
References:
- https://alligator.io/angular/Custom-webpack-config/
- https://github.com/angular/angularfire/blob/master/docs/universal/getting-started.md#3-add-a-webpack-config-for-the-express-server
- WebpackError: ReferenceError: IDBIndex is not defined while building with Gatsby.JS (ver #2.15.21) firebase/firebase-js-sdk#2222 (comment)
Hi there, your solution fix the "IDBIndex is not defined" error, but throws the following error:
I assume this fix wont work with Angular SSR?
Thanks
EDIT: fix for my last image, dont use ANYTHING related to firebase in app.component.ts (don't inject services that use firebase either), if you do that, the app will serve:ssr and work everything fine. I had to lazyload my modules which are using firebase, and move some logic which was firebase related to such modules. Now my app is serving in SSR mode just fine.
I hope in the future they fix this.
So to summarise: do @kgajera solution, and if you encounter the same problem as me, try my solution on top of that.
I'm using Angular 13.2.6
Downgrading still the best solution ?
I really do not know. I can't do regression due to technical requirements of some dependencies. so i'm waiting for the proper solution.
The issue has already been opened in the appropriate project and I believe they are already looking: https://github.com/firebase/firebase-js-sdk/issues/6042
Our team has all the latest versions of NX and NG (13.2) we were able to get rid of this problem by downgrading one package.
"@angular-devkit/build-angular": "^13.0.4",
Our team has all the latest versions of NX and NG (13.2) we were able to get rid of this problem by downgrading one package.
"@angular-devkit/build-angular": "^13.0.4",
This does the job.
Our team has all the latest versions of NX and NG (13.2) we were able to get rid of this problem by downgrading one package.
"@angular-devkit/build-angular": "^13.0.4",
This does not work in my case, would you share your full package.json?
Our team has all the latest versions of NX and NG (13.2) we were able to get rid of this problem by downgrading one package.
"@angular-devkit/build-angular": "^13.0.4",
This does not work in my case, would you share your full package.json?
here is my package.json. I also got error regarding some version mismatch. For that I had to add browser names statically in my package.json to work. After this I was able to run SSR build and SSR serve with no issue. Hope you find it helpful.
"browserslist": [
"and_chr 97",
"and_ff 95",
"and_qq 10.4",
"and_uc 12.12",
"baidu 7.12",
"chrome 97",
"chrome 96",
"chrome 95",
"chrome 94",
"edge 97",
"edge 96",
"firefox 96",
"firefox 95",
"firefox 94",
"firefox 91",
"firefox 78",
"ios_saf 15.0-15.1",
"ios_saf 14.0-14.4",
"kaios 2.5",
"op_mini all",
"op_mob 64",
"opera 82",
"safari 13.1",
"samsung 16.0",
"samsung 15.0"
],
"resolutions": {
"webpack": "^5.0.0-beta.30"
},
"dependencies": {
"@angular-material-components/datetime-picker": "6.0.3",
"@angular/animations": "^13.2.6",
"@angular/cdk": "^13.2.6",
"@angular/common": "13.3.0",
"@angular/compiler": "13.3.0",
"@angular/core": "13.3.0",
"@angular/fire": "^6.1.4",
"@angular/forms": "13.3.0",
"@angular/material": "13.3.0",
"@angular/material-moment-adapter": "13.3.0",
"@angular/platform-browser": "13.3.0",
"@angular/platform-browser-dynamic": "13.3.0",
"@angular/platform-server": "13.3.0",
"@angular/router": "13.3.0",
"@filestack/angular": "1.4.0",
"@fortawesome/fontawesome-free": "^5.15.4",
"@fullcalendar/angular": "4.4.5-beta",
"@fullcalendar/core": "4.4.2",
"@fullcalendar/daygrid": "4.4.2",
"@fullcalendar/interaction": "4.4.2",
"@fullcalendar/list": "4.4.2",
"@fullcalendar/moment": "4.4.2",
"@fullcalendar/rrule": "4.4.2",
"@fullcalendar/timegrid": "4.4.2",
"@nguniversal/express-engine": "^12.0.0",
"@types/jspdf": "^1.3.3",
"@types/stripe": "^7.13.25",
"algoliasearch": "^4.12.1",
"angular-olark": "^1.0.0",
"aos": "^2.3.4",
"apexcharts": "^3.26.1",
"bootstrap": "^5.1.3",
"crypto-browserify": "^3.12.0",
"crypto-js": "^4.0.0",
"domino": "^2.1.6",
"express": "^4.15.2",
"filestack-js": "^3.23.1",
"firebase": "^8.10.1",
"highlight.js": "10.7.2",
"jquery": "^3.6.0",
"jspdf": "^2.5.1",
"jspdf-autotable": "^3.5.23",
"lodash-es": "4.17.21",
"moment": "^2.29.1",
"ng-apexcharts": "^1.5.9",
"ng-starrating": "^1.0.20",
"ng-stripe-checkout": "^1.0.4",
"ng-wistia-components": "0.0.2",
"ngx-device-detector": "^2.0.8",
"ngx-hotjar": "^11.0.0",
"ngx-infinite-scroll": "^10.0.1",
"ngx-mat-select-search": "^3.2.0",
"ngx-moment": "^5.0.0",
"ngx-quill": "^16.2.0",
"ngx-tooltip": "0.0.9",
"node-fetch": "^2.6.1",
"perfect-scrollbar": "1.5.0",
"quill": "1.3.7",
"rrule": "2.6.8",
"rxjs": "7.5.5",
"source-map-explorer": "^2.5.2",
"stripe": "^8.116.0",
"stripe-angular": "^1.2.1",
"tslib": "2.2.0",
"web-animations-js": "2.3.2",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "13.0.4",
"@angular/cli": "13.3.0",
"@angular/compiler-cli": "13.3.0",
"@angular/language-service": "13.3.0",
"@nguniversal/builders": "^12.0.0",
"@ngx-builders/analyze": "^2.3.0",
"@types/crypto-js": "4.0.1",
"@types/express": "^4.17.0",
"@types/highlight.js": "9.12.4",
"@types/jasmine": "3.6.10",
"@types/jasminewd2": "2.0.8",
"@types/lodash-es": "4.17.4",
"@types/node": "15.0.1",
"bufferutil": "^4.0.3",
"codelyzer": "6.0.2",
"jasmine-core": "3.7.1",
"jasmine-spec-reporter": "7.0.0",
"karma": "6.3.2",
"karma-chrome-launcher": "3.1.0",
"karma-coverage-istanbul-reporter": "3.0.3",
"karma-jasmine": "4.0.1",
"karma-jasmine-html-reporter": "1.5.4",
"ngx-owl-carousel-o": "^6.0.0",
"protractor": "7.0.0",
"tailwindcss": "2.1.2",
"ts-node": "9.1.1",
"tslint": "6.1.2",
"typescript": "~4.4.0",
"utf-8-validate": "^5.0.5",
"ws": "^8.2.2",
"xhr2": "^0.2.1"
}
}
I really do not know. I can't do regression due to technical requirements of some dependencies. so i'm waiting for the proper solution.
The issue has already been opened in the appropriate project and I believe they are already looking: firebase/firebase-js-sdk#6042
Are you still facing issue ? They said they had release the fixed on Firebase version 9.6.9. I am using firebase 8 so not able to make it work so far. Aren't you able to build and run the app ?
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.
Which @angular/* package(s) are the source of the bug?
Don't known / other
Is this a regression?
Yes
Description
After upgrading to angular 13.10 from 13.03, pre-rending the app fails with the "IDBIndex is not defined" error.
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run
ng version
)Anything else?
Reverting back to 13.03 resolves this error.