-
Notifications
You must be signed in to change notification settings - Fork 893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Angular ssr compilation issue #1455
Comments
I found a few problems with this issue:
|
I don't quite understand your use case here. What do you mean by deploying to firebase functions? I assume you are making a web app that runs in browsers, then I don't understand what you are deploying to firebase function. Can you please clarify? |
Hi @Feiyang1 , I think he got into the same issue with me. As i posted a question on stackoverflow at this link. When trying with angular severside rendering, at step 5 it shows that "TypeError: Cannot read property 'stringify' of undefined" and after take a look on the trace it show that the error comes from '/node_modules/@firebase/webchannel-wrapper/dist/index.esm.js' Could you help to give a look? |
Okay. I think I know what's going on here - the browser bundle of firestore is included in your server bundle that runs in node. I couldn't reproduce the exact same error that you saw, but I think it is it. Basically when you bundle your server code with webpack, it prioritizes the module script over the main script. Firesbase defines both module script and main script, and the module script is packaged specifically for the browser use case, so it fails when you run it in node. The workaround is to exclude firestore in the server bundle and load it dynamically in the runtime. Add // change the regex to include the packages you want to exclude
const regex = /firebase\/(app|firestore)/;
// copied from the Angular SSR tutorial
module.exports = {
entry: { server: './server.ts' },
resolve: { extensions: ['.js', '.ts'] },
target: 'node',
mode: 'none',
// this makes sure we include node_modules and other 3rd party libraries
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();
}],
....
}; Hope it helps! |
@Feiyang1 thank you so much for you solution, works like a charm! I will provide my context and what I did to solve the error, so maybe can help someone encountering the same issue.
This solved the window error, but then I encountered the Then I had some problems in my app with the following solutions:
where the platformService related code is the following:
Hope it helps everyone struggling with the same issue! Enjoy 🥳 |
Thank you for your help @Feiyang1 The instruction in this link seems not updated, because the code in the provided repo is quite diffirent and more important that it works even with firestore without any new config (the way @Feiyang1 point out) I did clone the repo and then tried to add firestore on it and everything just worked properly. So, now you have two choices: go with the instruction and apply the fix from @Feiyang1 OR just clone the repo and checkout the way they implement SSR. Thanks! |
@langhoangal do you mean the code downloaded clicking "Download the finished sample code"? Did you figured out what was different? From a quick look the code looks equal (checked the webpack and server config) |
@langhoangal thx! I checked out the repo and made a comparison: the main differences are the compilation using tsc instead of webpack and some tsconfigs options. Removing the webpack usage popped out errors because of issues with libraries like Nolanus/ngx-page-scroll#212 not commonjs compatible. Looking at angular/universal-starter#626 (comment) looks like they also reverted the removal of webpack because of the ecosystem. I'll personally stick with @Feiyang1 workaround for now until libraries enable more support for SSR |
Does anybody know how to resolve this with VueJS Unit:Testing with Mocha
Warning: This is a browser-targeted Firebase bundle but it appears it is being If you are using Webpack, you can specify “main” as the first item in |
Hi, Thank you in advance for your answers. /Users/v3zir/Documents/project/angular/angular-universal-starter/node_modules/protobufjs/src/root.js:234 |
@v3zir I can replicate this. Locally changing |
I tried to solve window issue as you mention then i get this error.. Error: ENOENT: no such file or directory, open '\dist\index.html' still got this error Error: ENOENT: no such file or directory, open '\dist\index.html' |
hello All, I tried all the suggested methods but still getting the error. Though i'm getting ReferenceError: XMLHttpRequest is not defined please help. |
I get this error on applying window solution can u help with it Error: not supported |
You are not likely getting help by replying to a closed issue. It's also hard to have a focused conversation with so many different issues. Please open a new issue if you are facing problems. |
@jwoodmansey your solution works, but more precisely:
Super nasty bug, something should be done about this and the topic opened again. Basically I got this with the Environment:
Now Angular Universal (SSR) works again, |
The problem is... how to deploy it? On
Edit, I was able to make it that way:
Still, hope so it'll be resolved with the |
My final solution was to change this simple line, and upload it to a separated repo (https://github.com/danieldanielecki/protobufjs-angularfire). Then in |
I have integrated Angular 7.0, Angular Universal 7.0.2 and @angular/fire 5.1.1 .
I am able to run the project using ng build command .
When I am trying to compile it and deploy it on firebase functions . I am getting error as below
TypeError: Cannot read property 'stringify' of undefined
I dig into issue and I found that @firebase/webchannel-wrapper index.js file has a code as below
var ub=h.JSON.stringify;
and due to this I am not able to deploy the application.
Hope, you understand my issue and will get quick reply for this.
Thanks.
The text was updated successfully, but these errors were encountered: