query icon indicating copy to clipboard operation
query copied to clipboard

`@tanstack/eslint-plugin-query` missing (peer) dependency on `typescript`

Open anomiex opened this issue 7 months ago • 4 comments

Describe the bug

@tanstack/eslint-plugin-query tries to import typescript, but does not declare it as a dependency or peer dependency.

This happens to work with npm's hoisting due to other dependencies pulling that package in, but will fail with yarn's p'n'p or pnpm with hoisting disabled.

Your minimal, reproducible example

Reproduction steps explain how to reproduce starting with an empty directory.

Steps to reproduce

With yarn:

  1. Create a temporary directory, and cd into it.
  2. echo '{}' > package.json
  3. yarn set version stable
  4. yarn add eslint @tanstack/eslint-plugin-query
  5. echo 'import pluginQuery from "@tanstack/eslint-plugin-query"; export default [ ...pluginQuery.configs["flat/recommended"], ];' > eslint.config.mjs
  6. yarn exec eslint .

With pnpm:

  1. Create a temporary directory, and cd into it.
  2. echo 'hoist-pattern=[]' > .npmrc
  3. pnpm add eslint @tanstack/eslint-plugin-query
  4. echo 'import pluginQuery from "@tanstack/eslint-plugin-query"; export default [ ...pluginQuery.configs["flat/recommended"], ];' > eslint.config.mjs
  5. pnpm exec eslint .

Expected behavior

Eslint runs.

How often does this bug happen?

Every time

Screenshots or Videos

No video or screenshot, but the console output would seem to be helpful here.

With yarn:

Oops! Something went wrong! :(

ESLint: 9.25.1

Error: @tanstack/eslint-plugin-query tried to access typescript, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: typescript (via "typescript/package.json")
Required by: @tanstack/eslint-plugin-query@virtual:dc3fc578bfa5e06182a4d2be39ede0bc5b74940b1ffe0d70c26892ab140a4699787750fba175dc306292e80b4aa2c8c5f68c2a821e69b2c37e360c0dff36ff66#npm:5.74.7 (via /tmp/test/.yarn/__virtual__/@tanstack-eslint-plugin-query-virtual-135df79552/3/home/me/.yarn/berry/cache/@tanstack-eslint-plugin-query-npm-5.74.7-a9272f7a3e-10c0.zip/node_modules/@tanstack/eslint-plugin-query/build/modern/chunk-6ZHBB3IQ.js)

    at makeError (/tmp/test/.pnp.cjs:6959:34)
    at resolveToUnqualified (/tmp/test/.pnp.cjs:8600:21)
    at Object.resolveToUnqualified (/tmp/test/.pnp.cjs:8780:26)
    at resolve$1 (file:///tmp/test/.pnp.loader.mjs:2031:31)
    at nextResolve (node:internal/modules/esm/hooks:748:28)
    at Hooks.resolve (node:internal/modules/esm/hooks:240:30)
    at handleMessage (node:internal/modules/esm/worker:199:24)
    at Immediate.checkForMessages (node:internal/modules/esm/worker:141:28)
    at process.processImmediate (node:internal/timers:485:21)

With pnpm:

Oops! Something went wrong! :(

ESLint: 9.25.1

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'typescript' imported from /tmp/test/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@tanstack/eslint-plugin-query/build/modern/chunk-6ZHBB3IQ.js
    at Object.getPackageJSONURL (node:internal/modules/package_json_reader:268:9)
    at packageResolve (node:internal/modules/esm/resolve:768:81)
    at moduleResolve (node:internal/modules/esm/resolve:854:18)
    at defaultResolve (node:internal/modules/esm/resolve:984:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:780:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:704:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:687:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:305:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:137:49)

Platform

  • OS: Linux
  • Browser: N/A
  • Browser version: N/A
  • node version: v22.15.0
  • pnpm version: 10.10.0
  • yarn version: 4.9.1

Tanstack Query adapter

None

TanStack Query version

@tanstack/eslint-plugin-query v5.74.7

TypeScript version

none

Additional context

The attempt to import typescript is here:

https://github.com/TanStack/query/blob/18af64367c6435de0ad899108209a94ef2ba0b14/packages/eslint-plugin-query/src/rules/no-void-query-fn/no-void-query-fn.rule.ts#L2

Added in #8925.

anomiex avatar May 02 '25 20:05 anomiex

@Newbie012 we only need the typescript import because of the flags here:

https://github.com/TanStack/query/blob/993e838d5f564f3fdb6526611ed8ff05f59627fb/packages/eslint-plugin-query/src/rules/no-void-query-fn/no-void-query-fn.rule.ts#L81

we could just copy those two constants for our case to not rely on typescript at runtime ?

TkDodo avatar May 03 '25 06:05 TkDodo

@TkDodo That's correct, but it does make sense to to add typescript as an optional peer dependency. We could leverage the type checker for additional enforcements when needed. But maybe I'm getting ahead of myself.

Newbie012 avatar May 09 '25 06:05 Newbie012

Yeah that’s also fine for me, but if we import from it, it can’t be optional, right?

TkDodo avatar May 09 '25 07:05 TkDodo

Any update on this issue ? I'm stuck on 5.71.5. Using 5.72.0 with Yarn PnP mode, eslint fails to execute:

Error: @tanstack/eslint-plugin-query tried to access typescript, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Jul13nT avatar Oct 09 '25 11:10 Jul13nT