`@tanstack/eslint-plugin-query` missing (peer) dependency on `typescript`
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:
- Create a temporary directory, and cd into it.
echo '{}' > package.jsonyarn set version stableyarn add eslint @tanstack/eslint-plugin-queryecho 'import pluginQuery from "@tanstack/eslint-plugin-query"; export default [ ...pluginQuery.configs["flat/recommended"], ];' > eslint.config.mjsyarn exec eslint .
With pnpm:
- Create a temporary directory, and cd into it.
echo 'hoist-pattern=[]' > .npmrcpnpm add eslint @tanstack/eslint-plugin-queryecho 'import pluginQuery from "@tanstack/eslint-plugin-query"; export default [ ...pluginQuery.configs["flat/recommended"], ];' > eslint.config.mjspnpm 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.
@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 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.
Yeah that’s also fine for me, but if we import from it, it can’t be optional, right?
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.