mpen
mpen

Reputation: 283325

TS7016: Could not find a declaration file for module 'faker/locale/en_CA'

I'm getting this error:

TS7016: Could not find a declaration file for module 'faker/locale/en_CA'. '.../myproject/node_modules/faker/locale/en_CA.js' implicitly has an 'any' type.

With this code:

import * as faker from 'faker/locale/en_CA';

The thing is, I installed @types/faker, and I can see that node_modules/@types/faker/index.d.ts does in fact include:

declare module "faker/locale/en_CA" {
    export = fakerStatic;
}

So the module has been declared, but TS can't find it for some reason.

Here's my tsconfig:

{
    "compilerOptions": {
        "strict": true,
        "importHelpers": false,
        "inlineSources": true,
        "noEmitOnError": true,
        "pretty": true,
        "module": "commonjs",
        "noImplicitAny": true,
        "suppressImplicitAnyIndexErrors": true,
        "removeComments": true,
        "preserveConstEnums": false,
        "sourceMap": true,
        "lib": ["es2017","esnext.asynciterable"],
        "skipLibCheck": true,
        "outDir": "dist",
        "target": "es2018",
        "declaration": true,
        "types" : ["node"],
        "resolveJsonModule": true,
        "esModuleInterop": false,
        "baseUrl": ".",
        "paths": {
            "*": ["types/*"]
        }
    },

    "files": [
        "src/main"
    ],
    "exclude": [
        "node_modules"
    ]
}

Am I missing something?


Note that

import * as faker from 'faker';

Works perfectly fine.

Both VSCode and PhpStorm can find 'faker/locale/en_CA' no problemo, it's just tsc that can't.

Upvotes: 2

Views: 3917

Answers (2)

Mark
Mark

Reputation: 18877

Four years later I got a similar error.

Updating to TypeScript 4.* helped.

See https://github.com/faker-js/faker/issues/606

Upvotes: 2

Matt McCutchen
Matt McCutchen

Reputation: 30989

Try removing "types" : ["node"] from tsconfig.json. According to the documentation, that line is saying you don't want TypeScript to load types for any package other than node.

Upvotes: 3

Related Questions