Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

TypeScript says a JavaScript module implicitly has an any type

ErrorCould not find a declaration file for module 'react-materialize'. 'path/to/module-name.js' implicitly has an 'any' type.

Short answer

TypeScript found the JavaScript file but no types for it, and noImplicitAny turns that into an error. Install the matching @types package if one exists, check whether the package ships its own declarations, or write a small ambient module declaration yourself.

  • Applies to TypeScript 5, webpack 5, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Note the module name in the error, then ask npm whether a types package exists for it.

    npm view @types/react-materialize name version
  2. 2Match what you see, then jump to its fix

    1. 1npm view returns a name and version for @types/<module>The types live in a separate @types packageFix
    2. 2npm view finds no @types package, and the package has no types in its own filesNo declarations exist, so the import has no typesFix

What does the error look like?

  • Could not find a declaration file for module 'react-materialize'. 'path/to/module-name.js' implicitly has an 'any' type.

Cause 1 of 2

The types live in a separate @types package

1Check

@types packages usually carry the same name as the npm package, with an @types/ prefix.

npm view @types/<module-name> name version

2Fix

Install it as a dev dependency.

npm install --save-dev @types/<module-name>

3Verify

Run the compiler; the error for that module should be gone.

npx tsc --noEmit

Confirmed by typescriptlang.org

Did this fix it?

Cause 2 of 2

No declarations exist, so the import has no types

1Check

When no declarations are found, TypeScript resolves to the JavaScript file, which gives no types and raises the error while noImplicitAny is on. noImplicitAny is on by default when strict is enabled.

grep -n "strict\|noImplicitAny" tsconfig.json

2Fix

Write an ambient module declaration in a .d.ts file that is included by tsconfig, and describe only what you use. It must not contain a top-level import or export, or it stops being an ambient declaration.

// src/types/react-materialize.d.ts
declare module "react-materialize" {
  export const Button: any;
  export const Row: any;
}

3Verify

Make sure tsconfig includes that folder, then compile.

npx tsc --noEmit

Confirmed by typescriptlang.org

Did this fix it?

How do I stop it coming back?

  • Prefer packages that ship their own declarations; then no @types package is needed.
  • Keep hand-written declarations in one folder and list it in tsconfig include.
  • Keep noImplicitAny on and write small declarations instead of turning strict off.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

Jest fails to parse a React Native or Expo dependency

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax

Jest does not run Babel on node_modules by default, and many React Native packages ship untranspiled source.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.