natemoo-re / astro-icon

Inline and sprite-based SVGs in Astro made easy!
https://astroicon.dev
Other
1.08k stars 60 forks source link

[v1] Unable to locate `@iconify-json/*` packages on build when installed with pnpm, npm #173

Closed josefaidt closed 9 months ago

josefaidt commented 9 months ago

What version of astro-icon are you using?

v1.0.0

Astro Info

Astro                    v4.0.7
Node                     v20.9.0
System                   macOS (arm64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             astro-icon
                         @astrojs/mdx
                         @astrojs/sitemap
                         @astrojs/tailwind

If this issue only occurs in one browser, which browser is a problem?

n/a

Describe the Bug

similar error to https://github.com/natemoo-re/astro-icon/issues/165, but when using pnpm builds are failing. when poking around the repo and debugging this, it appears pnpm list's behavior changes depending on how NODE_ENV is set:

➜  NODE_ENV=production pnpm list --json
[
  {
    "name": "josef.dev",
    "version": "3.0.0-next.0",
    "path": "/Users/josef/Documents/projects/josef.dev-2",
    "private": true,
  }
]

vs without NODE_ENV

➜  pnpm list --json
[
  {
    "name": "josef.dev",
    "version": "3.0.0-next.0",
    "path": "/Users/josef/Documents/projects/josef.dev-2",
    "private": true,
    "devDependencies": {
      "@astrojs/check": {
        "from": "@astrojs/check",
        "version": "0.3.4",
        "resolved": "https://registry.npmjs.org/@astrojs/check/-/check-0.3.4.tgz",
        "path": "/Users/josef/Documents/projects/josef.dev-2/node_modules/.pnpm/@astrojs+check@0.3.4_prettier@3.1.1_typescript@5.3.3/node_modules/@astrojs/check"
      },
      "@astrojs/mdx": {
        "from": "@astrojs/mdx",
        "version": "2.0.2",
        "resolved": "https://registry.npmjs.org/@astrojs/mdx/-/mdx-2.0.2.tgz",
        "path": "/Users/josef/Documents/projects/josef.dev-2/node_modules/.pnpm/@astrojs+mdx@2.0.2_astro@4.0.7/node_modules/@astrojs/mdx"
      },
      "@astrojs/rss": {
        "from": "@astrojs/rss",
        "version": "4.0.1",
        "resolved": "https://registry.npmjs.org/@astrojs/rss/-/rss-4.0.1.tgz",
        "path": "/Users/josef/Documents/projects/josef.dev-2/node_modules/.pnpm/@astrojs+rss@4.0.1/node_modules/@astrojs/rss"
      },
      "@astrojs/sitemap": {
        "from": "@astrojs/sitemap",
        "version": "3.0.3",
        "resolved": "https://registry.npmjs.org/@astrojs/sitemap/-/sitemap-3.0.3.tgz",
        "path": "/Users/josef/Documents/projects/josef.dev-2/node_modules/.pnpm/@astrojs+sitemap@3.0.3/node_modules/@astrojs/sitemap"
      },
      "@astrojs/tailwind": {
        "from": "@astrojs/tailwind",
        "version": "5.0.4",
        "resolved": "https://registry.npmjs.org/@astrojs/tailwind/-/tailwind-5.0.4.tgz",
        "path": "/Users/josef/Documents/projects/josef.dev-2/node_modules/.pnpm/@astrojs+tailwind@5.0.4_astro@4.0.7_tailwindcss@3.4.0/node_modules/@astrojs/tailwind"
      },
      "@iconify-json/gg": {
        "from": "@iconify-json/gg",
        "version": "1.1.9",
        "resolved": "https://registry.npmjs.org/@iconify-json/gg/-/gg-1.1.9.tgz",
        "path": "/Users/josef/Documents/projects/josef.dev-2/node_modules/.pnpm/@iconify-json+gg@1.1.9/node_modules/@iconify-json/gg"
      },
      "@iconify-json/simple-icons": {
        "from": "@iconify-json/simple-icons",
        "version": "1.1.85",
        "resolved": "https://registry.npmjs.org/@iconify-json/simple-icons/-/simple-icons-1.1.85.tgz",
        "path": "/Users/josef/Documents/projects/josef.dev-2/node_modules/.pnpm/@iconify-json+simple-icons@1.1.85/node_modules/@iconify-json/simple-icons"
      },
      "astro": {
        "from": "astro",
        "version": "4.0.7",
        "resolved": "https://registry.npmjs.org/astro/-/astro-4.0.7.tgz",
        "path": "/Users/josef/Documents/projects/josef.dev-2/node_modules/.pnpm/astro@4.0.7_typescript@5.3.3/node_modules/astro"
      },
      "astro-icon": {
        "from": "astro-icon",
        "version": "file:../astro-icon/packages/core",
        "path": "/Users/josef/Documents/projects/josef.dev-2/node_modules/.pnpm/file+..+astro-icon+packages+core/node_modules/astro-icon"
      },
      "prettier": {
        "from": "prettier",
        "version": "3.1.1",
        "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.1.1.tgz",
        "path": "/Users/josef/Documents/projects/josef.dev-2/node_modules/.pnpm/prettier@3.1.1/node_modules/prettier"
      },
      "prettier-plugin-packagejson": {
        "from": "prettier-plugin-packagejson",
        "version": "2.4.7",
        "resolved": "https://registry.npmjs.org/prettier-plugin-packagejson/-/prettier-plugin-packagejson-2.4.7.tgz",
        "path": "/Users/josef/Documents/projects/josef.dev-2/node_modules/.pnpm/prettier-plugin-packagejson@2.4.7_prettier@3.1.1/node_modules/prettier-plugin-packagejson"
      },
      "prettier-plugin-tailwindcss": {
        "from": "prettier-plugin-tailwindcss",
        "version": "0.5.9",
        "resolved": "https://registry.npmjs.org/prettier-plugin-tailwindcss/-/prettier-plugin-tailwindcss-0.5.9.tgz",
        "path": "/Users/josef/Documents/projects/josef.dev-2/node_modules/.pnpm/prettier-plugin-tailwindcss@0.5.9_prettier@3.1.1/node_modules/prettier-plugin-tailwindcss"
      },
      "tailwindcss": {
        "from": "tailwindcss",
        "version": "3.4.0",
        "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.0.tgz",
        "path": "/Users/josef/Documents/projects/josef.dev-2/node_modules/.pnpm/tailwindcss@3.4.0/node_modules/tailwindcss"
      },
      "typescript": {
        "from": "typescript",
        "version": "5.3.3",
        "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz",
        "path": "/Users/josef/Documents/projects/josef.dev-2/node_modules/.pnpm/typescript@5.3.3/node_modules/typescript"
      },
      "wrangler": {
        "from": "wrangler",
        "version": "3.22.1",
        "resolved": "https://registry.npmjs.org/wrangler/-/wrangler-3.22.1.tgz",
        "path": "/Users/josef/Documents/projects/josef.dev-2/node_modules/.pnpm/wrangler@3.22.1/node_modules/wrangler"
      }
    },
    "unsavedDependencies": {
      "volar-service-prettier": {
        "from": "volar-service-prettier",
        "version": "link:node_modules/.pnpm/volar-service-prettier@0.0.16_@volar+language-service@1.10.10_prettier@3.1.1/node_modules/volar-service-prettier",
        "path": "/Users/josef/Documents/projects/josef.dev-2/node_modules/.pnpm/volar-service-prettier@0.0.16_@volar+language-service@1.10.10_prettier@3.1.1/node_modules/volar-service-prettier"
      }
    }
  }
]

This also appears to fail with npm, yielding a similar result.

should this just always default to reading the package.json file? https://github.com/natemoo-re/astro-icon/blob/cb25022c82a5ff74f43b2f6def0532d79dfd2a6f/packages/core/src/loaders/loadIconifyCollections.ts#L94 it doesn't look like you can run something like NODE_ENV=production pnpm list --json --dev without also omitting dependencies, which may be undesirable

What's the expected result?

iconify packages are resolved when installed as devDependencies

Link to Minimal Reproducible Example

https://github.com/josefaidt/josef.dev/blob/v3

Pukimaa commented 9 months ago

Everything (build, dev, etc.) fails when doing it with npm (at least for me). The same error as in #165...Also tried yarn. I have all three icon packs I use installed as regular dependencies:

"dependencies": {
    "@iconify-json/fa-brands": "^1.1.8",
    "@iconify-json/mdi": "^1.1.63",
    "@iconify-json/twemoji": "^1.1.15"
  }

and also included them in the config, to be sure (also doesn't work either way). Also normally the list command only seems to be running if no agent was found.

Maybe the package.json checking is more reliable? Even if it would allow for it to not be installed, but just only added, which seems pretty unlikely if you also have astro etc. installed. I was able to make it work by removing the if else statement of https://github.com/natemoo-re/astro-icon/blob/main/packages/core/src/loaders/loadIconifyCollections.ts#L94-L114.

Pukimaa commented 9 months ago

@natemoo-re I hope this helps. Seems to be the issue of all the recent v1 issues created here. For now, I'd remove the else statement as a hotfix and work on the else statement a bit more :)

josefaidt commented 9 months ago

@Pukimaa thanks for adding your notes here :) it's interesting you're also seeing this issue in dev. That is fine on my end, and in my brief digging the <pm> list command should work as expected when NODE_ENV is not set to production