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

Build Failures with TypeScript's noUnusedLocals Compiler Option #160

Closed
vinoddotcom opened this issue Sep 4, 2024 · 13 comments
Closed

Build Failures with TypeScript's noUnusedLocals Compiler Option #160

vinoddotcom opened this issue Sep 4, 2024 · 13 comments

Comments

@vinoddotcom
Copy link

vinoddotcom commented Sep 4, 2024

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
Copy link
Member

userquin commented Sep 4, 2024

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

@vinoddotcom
Copy link
Author

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

@userquin
Copy link
Member

userquin commented Sep 4, 2024

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
Copy link
Author

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
Copy link
Member

userquin commented Sep 4, 2024

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 #161) working: https://stackblitz.com/edit/github-zjpmae-mvu5fh?file=nuxt.config.ts

@vinoddotcom
Copy link
Author

vinoddotcom commented Sep 5, 2024

@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
Copy link
Author

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

@vinoddotcom
Copy link
Author

vinoddotcom commented Sep 6, 2024

@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
Copy link
Member

userquin commented Sep 6, 2024

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

@vinoddotcom
Copy link
Author

@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
Copy link
Member

userquin commented Sep 9, 2024

It is fine on my local, using node 20.10.0.

@userquin
Copy link
Member

userquin commented Sep 10, 2024

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:

  • npm run clean-install
  • npm run clean-test

@vinoddotcom
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants