Skip to content
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

Ionic-Angular: ionicons do not load #880

Open
whydoievenneedthis opened this issue Dec 28, 2022 · 4 comments
Open

Ionic-Angular: ionicons do not load #880

whydoievenneedthis opened this issue Dec 28, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@whydoievenneedthis
Copy link

whydoievenneedthis commented Dec 28, 2022

Describe the bug
Having the following html fragment in a component:

<ion-icon name="add"></ion-icon>

The icon does not appear. There is an attempt to load the svg file, but it returns with a 404:

GET http://localhost:4200/svg/add.svg 404 (Not Found)

Trying to manually open the URL above causes the router to kick in and to redirect to the ** path.

In addition to that, when the application is built, there is no svg directory with the icon files anymore.

angular: 15.0.4
capacitor: 4.6.1
ionic: 6.4.1
ionicons: 6.0.4 (transitive)
nx: 15.4.1
nxext/capacitor: 15.2.0
nxext/ionic-angular: 15.1.0

To Reproduce
https://github.com/whydoievenneedthis/ionicons-not-loading

Expected behavior
The svg file is served correctly and the icon appears in the browser.

Additional context
Last time I know this was working, it was with Angular 13 and the old nxtend plugin (I only have two icons in some rarely visited pages, so it took me a while to notice this).
Downgrading to angular 14, nx 14, nxext 14 and ionicons 5 did not solve the issue.

@whydoievenneedthis whydoievenneedthis added the bug Something isn't working label Dec 28, 2022
@SimonCockx
Copy link
Contributor

SimonCockx commented Jan 1, 2023

@whydoievenneedthis In your project.json file, there should an assets path to the folder node_modules/ionicons/dist/ionicons/svg, i.e.,

...
  "targets": {
      "build": {
          "executor": "@angular-devkit/build-angular:browser",
          "outputs": ["{options.outputPath}"],
          "options": {
              ...
              "assets": [
                 ...,
                  {
                      "glob": "**/*.svg",
                      "input": "node_modules/ionicons/dist/ionicons/svg",  -----> THIS HERE
                      "output": "./svg"
                  }
              ],
...

Can you verify you have this configuration and that your node_modules folder contains the ionicons/dist/ionicons/svg path to the specific icons you would like to load?

@whydoievenneedthis
Copy link
Author

@SimonCockx the indicated line is present in the project.json file:
https://github.com/whydoievenneedthis/ionicons-not-loading/blob/main/apps/my-app/project.json#L21

However the node_modules folder does not have the dependency in it. It only appears under node_modules/.pnpm/[email protected]/node_modules/ionicons/dist/svg, suggesting that the issue is not related to the component versions but to the configuration vs. the package manager used.

I would have to add ionicons as an explicit dependency in order to force it to appear directly under node_modules.

@SimonCockx
Copy link
Contributor

SimonCockx commented Jan 2, 2023

@whydoievenneedthis I guess this is by design of pnpm. It enforces strict dependency resolution, so you cannot (should not) access transitive dependencies without explicitly stating them as a dependency of your project, as opposed to npm. (see https://pnpm.io/next/npmrc#shamefully-hoist)

Since you are directly depending on ionicons, I would say it is fair that you should also directly state ionicons as a dependency.

I'm not sure whether having to do this manually is desirable or not. Could we automatically add ionicons as an explicit dependency to package.json? At what point should we do so? What if you don't need it? I think the least we can do is document this somewhere.

@DominikPieper @whydoievenneedthis what do you think?

@DominikPieper
Copy link
Member

@SimonCockx mhh not sure yet. I’ll do Sonne experiments cause I usually don’t use pnpm that often. I plan to do some stuff around the ionic packages the next time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants