
Question:
I'm getting this error:
<blockquote>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.
</blockquote>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 <em>has</em> 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?
<hr />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.
Try removing "types" : ["node"]
from tsconfig.json. According to <a href="https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types" rel="nofollow">the documentation</a>, that line is saying you don't want TypeScript to load types for any package other than node
.