fix(angular): ng add @ionic/angular in standalone projects - #28523
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
|
Let me know if you have any questions on how to review. I can run through creating a new angular project, testing the schematic and looking at the diffs 👍 |
| "zone.js": ">=0.11.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@angular-devkit/core": "^14.0.0", |
There was a problem hiding this comment.
Unsure if this is related, but I get the following error when I try to run ionic serve:
liamdebeasi@MacBook-Pro angular-17 % ionic serve
> ng run app:serve --host=localhost --port=8100
[ng] Error: Unknown arguments: host, port
[ERROR] ng has unexpectedly closed (exit code 1).
This happens in ng16 and ng17.
There was a problem hiding this comment.
I don't believe the schematic updates should impact that. This schematic's execution context is purely for the ng add command. After that it has no usage.
For example if I use the dev-build to run ng add and then install the latest version of @ionic/angular I get the same exception when using ionic serve:
sean@MacBook-Air ~/d/i/i/a/angular-blank (main)> ionic serve
> ng run app:serve --host=localhost --port=8100
[ng] Error: Unknown arguments: host, port
Developers really should be using the start command script with their projects: npm start.
Edit: But we should probably track this problem for the Ionic CLI.
There was a problem hiding this comment.
Ok looked into this more. You cannot assume to use ionic serve in a new Angular project. If the project name is not "app" it won't work.
For example my project is called angular-blank, so the command would need to be:
ng run angular-blank:serve --host=localhost --port=8100
> ng run angular-blank:serve --host=localhost --port=8100
Initial Chunk Files | Names | Raw Size
polyfills.js | polyfills | 82.71 kB |
styles.css | styles | 32.69 kB |
main.js | main | 23.47 kB |
| Initial Total | 138.87 kB
Application bundle generation complete. [2.358 seconds]
Watch mode enabled. Watching for file changes...
➜ Local: http://localhost:8100/
Our schematic could change the project name, but I think that is extremely high risk to break a lot of things in the consumers project.
There was a problem hiding this comment.
If this problem happened before the dev build them I'm fine keeping it out of scope. I assumed you could use ionic serve because the ionic.config.json file was present, but maybe that's not the case.
There was a problem hiding this comment.
It looks like you can use the Ionic CLI if you provide the project name for your angular project. If a name is not provided it defaults to app.
e.g.:
ionic serve --project=angular-blank
liamdebeasi
left a comment
There was a problem hiding this comment.
Good to go once my final comment is addressed.
Issue number: Resolves #28514
What is the current behavior?
When using the
@ionic/angularschematic in an Angular 17 project (ng add @ionic/angular), developers will receive an error preventing the schematic from running.Additionally, the previous implementations of the schematic are out of sync with the current state of the Ionic starters:
variables.cssis empty and missing Ionic's defaultsionic.config.jsonis not createdWhat is the new behavior?
ng add @ionic/angularworks with Angular 17 projectsng add @ionic/angularhas fallback behavior for Angular 16 projects usingAppModulevariables.cssfrom Ionic starters@angular-devkit/schematicsand@schematics/angular.@ionic/angular-toolkitCLI configuration and schematics configuration in theangular.jsonionic.config.jsonDoes this introduce a breaking change?
Other information
Dev-build:
7.5.5-dev.11700239837.1925bbdbTo test this PR:
npm install -g @angular/cli@17ng new angular-17ng add @ionic/angular@7.5.5-dev.11700239837.1925bbdbprovideIonicAngular({})is added to theapp.config.tsionic.config.jsonwas createdangular.jsonwas updated with the@ionic/angular-devkitconfigurationsNow verify legacy behavior:
npm install -g @angular/cli@16ng new angular-16ng add @ionic/angular@7.5.5-dev.11700239837.1925bbdbIonicModule.forRoot({})is added to theapp.module.tsangular.jsonionic.config.jsonwas createdangular.jsonwas updated with the@ionic/angular-devkitconfigurations