Repository navigation
Description
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
Ionic Framework Version
- v4.x
- v5.x
- v6.x
Current Behavior
Folks, I'm using the brand new Ionic 6, trying to integrate it with Angular Universal through NestJs. It was working pretty well, until I noted that I was getting this error when running using server side rendering:
Menu: must have a "content" element to listen for drag events on.
After some time, I noticed that the <ion-menu-button> wasn't working. I tried using it programmatically using the MenuController, but it also didn't work.
I run the code without SSR and the button was working properly. So I went out to find out what was the issue and I found this issue (#21918 (comment)) where the solution apparently was to add @ionic/angular-server to my Angular AppModule. I did so, but now every time I try to access Angular's pages, I'm getting this error (in server console):
ReferenceError: Cannot access 'ActionSheet' before initialization
and this one (browser console):
Uncaught SyntaxError: Strict mode code may not include a with statement
I tried to search for those issues but sadly I couldn't find much related.
If I remove IonicServerModule from AppModule the code runs, but the button naturally still doesn't work.
I'm not sure why this is happening. Is there any error with the Ionic version I'm using? Any substantial package that I'm missing?
From the SSR standpoint I understand that menu's contentId looks for its sibling with same id as it, and since that document is not available in that context, in fact, the menu won't have any content at all. But in browser, that doesn't make much sense. I also tried to conditionally render <ion-menu> tags for platform browsers. The Menu: must have a "content" element to listen for drag events on. error disappear, but still <ion-menu-button> isn't working.
Any insights on this matter?
I really appreciate it, thanks in advance.
Expected Behavior
The menu button should work after the implementation of IonicServerModule.
Steps to Reproduce
For reproducing issue with IonicServerModule
- Download repo from code reproduction URL and Install dependencies;
- Try running
npm run dev:ssrornpm run serve:ssr; - Check logs on console when trying to access
localhost:4200.
For reproducing issue with <ion-menu-button> not working / Menu: must have a "content" element to listen for drag events on.:
- Download repo from code reproduction URL;
- Remove
IonicServerModulefrom AppModule (src/app/app.module.ts); - Run
npm run dev:ssrornpm run serve:ssr; - Access localhost:4200/home;
- Resize screen to <768px;
- Click on hamburger icon at top right corner of the screen.
Code Reproduction URL
Ionic Info
Ionic:
Ionic CLI : 6.18.1 (/usr/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 6.0.5
@angular-devkit/build-angular : 13.1.4
@angular-devkit/schematics : 13.1.4
@angular/cli : 13.1.4
@ionic/angular-toolkit : 4.0.0
Utility:
cordova-res : not installed globally
native-run (update available: 1.5.0) : 1.4.1
System:
NodeJS : v16.13.2 (/home/dina/.nvm/versions/node/v16.13.2/bin/node)
npm : 8.1.2
OS : Linux 5.13
Additional Information
Content related with cannot access "action-sheet" before initialization:
#24448
Content related with Uncaught SyntaxError: Strict mode code may not include a with statement:
https://stackoverflow.com/questions/60114758/uncaught-syntaxerror-strict-mode-code-may-not-include-a-with-statement
Activity
[-]bug: [/-][+]bug: Ionic/angular 6 not working properly with @ionic/angular-server package[/+]liamdebeasi commentedon Feb 4, 2022
Thanks for the issue. The Action Sheet error was fixed via 897ae4a and a fix will be available in an upcoming release of Ionic.
As for the
contentIdwarning, using the@ionic/angular-serverpackage should resolve that issue as you noted. In order for SSR to work as intended in Ionic Angular, you must use the@ionic/angular-serverpackage.I am trying to understand the
Uncaught SyntaxError: Strict mode code may not include a with statementerror but I cannot get your app to run. I get the following error:Can you double check your reproduction case and make sure it has all the information I need to run the app?
vitordhers commentedon Feb 4, 2022
@liamdebeasi , thanks for your prompt response and awesome support. The issue you mentioned was due to I added src/environments to the .gitignore.
I updated repo and cloned it, now it's working, if you want to retry.
Besides, I'm eager to receive any news on that future release.
Once again, thanks a lot.
liamdebeasi commentedon Feb 4, 2022
Thanks! I have a dev build with the Action Sheet fix:
After installing the dev build, I do not get the action sheet or strict errors. Can you try that dev build and let me know if it resolves the issue?
vitordhers commentedon Feb 5, 2022
Hello Liam, thanks again for your support. I've cloned my repo (I've made for reproduction in my folder, in order to assure it was working, before submitting to you.), tried installing the dev packages, got a dependency error, though (please, find the logs below). I was able to install the dependencies (first the
@ionic/angular, then@ionic/angular-serverwith --force argument). I've got some errors, deletednode_modulesandpackage-lock.json, runnpm install again, and in order for it to work I had to use --force argument too. Then it installed correctly, the code run, but so far, I'm still getting this error in browser console:Uncaught SyntaxError: Strict mode code may not include a with statement.I'm also getting this error in server console:
TypeError: Cannot read properties of null (reading 'whenDefined')The
ion-menu-buttondoesn't show its icon and also is not working. I'm pretty sure that's not my code fault, since with regularnpm run startcommand it does.Please let me know if you need anything else from me, and again, thanks for your support.
ps.: I've updated the repo with latest changes
---------- npm install full log
[-]bug: Ionic/angular 6 not working properly with @ionic/angular-server package[/-][+]bug: angular, cannot read property of 'whenDefined' with ssr[/+]3 remaining items
Tvde1 commentedon Jun 30, 2022
Any idea when this will be resolved? It's a bummer not to have SSR. Bing apparently doesn't like rendering SPAs and refuses to index my site
DavidWiesner commentedon Jul 1, 2022
I often use stencil + ionic with SSG what didn't work anymore with ionic 6.
Tvde1 commentedon Jul 4, 2022
It is reproducible by following https://ionicframework.com/blog/ssr-with-angular-universal-and-ionic/ but with the
sidemenustarter instead ofblank.So you do:
1. Create the project
ionic start myApp sidemenu --type angular cd myApp npm install @angular/animations ng add @nguniversal/express-engine npm install @ionic/angular-server(you might need to run
npx ionic start ...)2. Enable Ionic SSR
And updating
app.server.module.tswith:import { NgModule } from '@angular/core'; import { ServerModule } from '@angular/platform-server'; import { AppModule } from './app.module'; import { AppComponent } from './app.component'; + import { IonicServerModule } from '@ionic/angular-server'; @NgModule({ imports: [ AppModule, ServerModule, + IonicServerModule ], bootstrap: [AppComponent], }) export class AppServerModule {}3. Run
Build & serve the application with:
(
npm run dev:ssris broken because some of theangular.jsonis missing adevelopmentconfiguration)4. Visit localhost:4000
When you visit localhost with javascript off (on chrome,
Ctrl+Shift+Pand run the "disable javascript" action), you will not see the sidebar. If you enable javascript, you will see the sidebar)The error logged to the console is:
I hope this helps 🙂
ngochiencse commentedon Jul 7, 2022
I also encounter this issue just like @Tvde1
CoooWeee commentedon Sep 28, 2022
I also get:
Menu: must have a "content" element to listen for drag events on.
Using:
Code:
Inside of "connectedCallback" (controllerion-menu_3.entry.js:112) "contentId" is undefined although I did set it.
cmoztas commentedon Oct 17, 2022
Any updates?
agustinhaller commentedon Jan 21, 2023
Hi @liamdebeasi are there any work in progress on this issue? Or maybe an idea on how it should be fixed?
MilotH2 commentedon Feb 22, 2023
I am encountering the same error. The first time the page loads, the ion-menu works, but on refresh it stops working.
package.json
"dependencies": { "@angular/animations": "^15.1.1", "@angular/common": "^15.1.1", "@angular/core": "^15.1.1", "@angular/forms": "^15.1.1", "@angular/platform-browser": "^15.1.1", "@angular/platform-browser-dynamic": "^15.1.1", "@angular/platform-server": "^15.1.1", "@angular/router": "^15.1.1", "@byteowls/capacitor-oauth2": "^4.0.0", "@capacitor/android": "4.6.2", "@capacitor/app": "^4.1.1", "@capacitor/core": "^4.6.2", "@capacitor/haptics": "^4.1.0", "@capacitor/ios": "4.6.2", "@capacitor/keyboard": "^4.1.1", "@capacitor/status-bar": "^4.1.1", "@ionic/angular": "^6.5.0", "@ionic/angular-server": "^6.5.0", "@jcesarmobile/ssl-skip": "0.2.0", "@nguniversal/express-engine": "^15.1.0", "express": "^4.15.2", "ionicons": "^6.1.1", "rxjs": "~7.5.0", "tslib": "^2.3.0", "zone.js": "~0.11.4" }, "devDependencies": { "@angular-devkit/build-angular": "^15.1.2", "@angular-eslint/builder": "^15.2.0", "@angular-eslint/eslint-plugin": "^15.2.0", "@angular-eslint/eslint-plugin-template": "^15.2.0", "@angular-eslint/template-parser": "^15.2.0", "@angular/cli": "^15.1.2", "@angular/compiler": "^15.1.1", "@angular/compiler-cli": "^15.1.1", "@angular/language-service": "^15.1.1", "@capacitor/cli": "^4.6.2", "@ionic/angular-toolkit": "^7.0.0", "@nguniversal/builders": "^15.1.0", "@types/express": "^4.17.0", "@types/jasmine": "~4.0.0", "@types/node": "^12.11.1", "@typescript-eslint/eslint-plugin": "5.3.0", "@typescript-eslint/parser": "5.3.0", "eslint": "^7.6.0", "eslint-plugin-import": "2.22.1", "eslint-plugin-jsdoc": "30.7.6", "eslint-plugin-prefer-arrow": "1.2.2", "jasmine-core": "~4.3.0", "jasmine-spec-reporter": "~5.0.0", "karma": "~6.4.0", "karma-chrome-launcher": "~3.1.0", "karma-coverage": "~2.2.0", "karma-coverage-istanbul-reporter": "~3.0.2", "karma-jasmine": "~5.1.0", "karma-jasmine-html-reporter": "~2.0.0", "ts-node": "~8.3.0", "typescript": "~4.8.4" },ionic info
`
Ionic:
Ionic CLI : 6.20.3 (C:\ProgramData\nvm\v18.12.1\node_modules@ionic\cli)
Ionic Framework : @ionic/angular 6.5.0
@angular-devkit/build-angular : 15.1.2
@angular-devkit/schematics : 15.1.2
@angular/cli : 15.1.2
@ionic/angular-toolkit : 7.0.0
Capacitor:
Capacitor CLI : 4.6.2
@capacitor/android : 4.6.2
@capacitor/core : 4.6.2
@capacitor/ios : 4.6.2
Utility:
cordova-res : not installed globally
native-run : 1.7.1
System:
NodeJS : v18.12.1 (C:\Program Files\nodejs\node.exe)
npm : 8.19.2
OS : Windows 10
`
liamdebeasi commentedon Feb 23, 2023
Hi there,
Can everyone try the following dev build and let me know if it resolves the issue in your apps?
Please note that this dev build only fixes the
Cannot read properties of null (reading 'whenDefined')error. Other Ionic-related SSR errors should be reported in separate issues.DavidWiesner commentedon Feb 24, 2023
Yes this works for my case in a pure stencil-ionic app with
npm install @ionic/[email protected]. Now the ssg works in this case. I do not have any projects with angular and ssg. Thanks!fix(menu, split-pane): ssr does not fail on null customElements check (…
liamdebeasi commentedon Mar 2, 2023
Thanks for the issue. This has been resolved via #26854, and a fix will be available in an upcoming release of Ionic Framework. Please feel free to continue testing the dev build, and let me know if you run into any issues with it.
ionitron-bot commentedon Apr 1, 2023
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.