vite-pwa / nuxt

Zero-config PWA Plugin for Nuxt 3
https://vite-pwa-org.netlify.app/frameworks/nuxt
MIT License
449 stars 22 forks source link

Build Failures with TypeScript's noUnusedLocals Compiler Option #160

Closed vinoddotcom closed 2 weeks ago

vinoddotcom commented 1 month ago

In Nuxt.js project that uses TypeScript, enabling the noUnusedLocals option in tsconfig.json causes the build to fail.

Screenshot: Screenshot from 2024-09-04 18-28-03

Minimum Reproduction: https://stackblitz.com/edit/github-zjpmae?file=package.json

Steps:

  1. npm i
  2. npm run test
  3. See error
userquin commented 1 month ago

Did you have @vite-pwa/assets-generator installed?

vinoddotcom commented 1 month ago

No, i did't install @vite-pwa/assets-generator

userquin commented 1 month ago

upps, forgot it, I'm going to release a new patch version in a few minutes, I need to remove unused import (try adding vite-plugin-pwa dependency in your reproduction):

imagen

vinoddotcom commented 1 month ago

Please take a look at the screenshot related to the project I’m currently working on. There were multiple import errors initially flagged as 'not found.' However, after disabling the noUnusedLocals rule in the TypeScript configuration, these errors were resolved.

userquin commented 1 month ago

No idea why checking types from node_modules, here your reproduction (moved noUnusedLocals to nuxt config file, added vite-plugin-pwa and using nuxt pwa from this PR https://github.com/vite-pwa/nuxt/pull/161) working: https://stackblitz.com/edit/github-zjpmae-mvu5fh?file=nuxt.config.ts

vinoddotcom commented 1 month ago

@userquin Here is a minimum reproduction of my case where multiple import errors were initially flagged as 'not found.

Minimum Reproduction: https://stackblitz.com/edit/github-yp7irr?file=package.json

I used to register the service worker through the plugins folder. Check: plugins -> init.client.ts

Steps:

  1. npm run clean-install
  2. npm run clean-test
  3. See error
vinoddotcom commented 1 month ago

@userquin Node_module is excluded in tsconfig.json, but somehow it still checks all .vue files including node_modules.

vinoddotcom commented 1 month ago

@userquin After running

npm run clean-install
npm run clean-test

I found these lines in ./nuxt/tsconfig.json, which is why TypeScript checks those files inside the node module.

    "../node_modules/@vite-pwa/nuxt/runtime",
    "../node_modules/@vite-pwa/nuxt/dist/runtime",

In node_modules/@vite-pwa/nuxt/dist/runtime, file types are imported with #build/. This is configured in ./nuxt/tsconfig.json. as

      "#build/": [
        "./"
      ],

In general, the default character we use is either ~/ or @/, which is configured in ./nuxt/tsconfig.json as such.

      "~/*": [
        "../*"
      ],
      "@/*": [
        "../*"
      ],

Could you please check if it should be #build/ or @/?

userquin commented 1 month ago

It should be #build/ since the types are generated inside the .nuxt folder, check pwa-icons subfolder.

vinoddotcom commented 1 month ago

@userquin Here is a minimum reproduction of my case where multiple import errors were initially flagged as 'not found.

Minimum Reproduction: https://stackblitz.com/edit/github-yp7irr?file=package.json

I used to register the service worker through the plugins folder. Check: plugins -> init.client.ts

Steps:

  1. npm run clean-install
  2. npm run clean-test
  3. See error

@userquin Can you please investigate why this issue is occurring based on its reproduction (https://stackblitz.com/edit/github-yp7irr?file=package.json)?

userquin commented 1 month ago

It is fine on my local, using node 20.10.0.

userquin commented 1 month ago

can you update vue to 3.5.3? I'm getting some error using Nuxt 3.13.1 and internal useId:

  "devDependencies": {
    "@vite-pwa/nuxt": "0.10.5",
    "nuxt": "3.13.1",
    "typescript": "5.5.4",
    "vue": "^3.5.3",
    "vue-tsc": "2.1.6"
  },
  "resolutions": {
    "vue": "3.5.3"
  }

I also change the clean-test script in your SB reproduction to "clean-test": "rm -rf .output && npx nuxi prepare && npx nuxi typecheck": https://stackblitz.com/edit/github-yp7irr-36g6ny?file=package.json

Running works:

vinoddotcom commented 2 weeks ago

@userquin, thank you for your response. Everything is running fine now.