Why can't TypeScript find modules that are installed into 'node_modules'?

Viewed 7166

Given the following directory structure:

{project}/
  |-- node_modules/
  |    |-- lodash
  |-- src/
  |    |-- index.ts
  |-- lib/ (output)
  |    |-- index.js
  |    |-- index.d.ts
  |-- package.json
  |-- tsconfig.json

Whilst the built output functions properly; the tsc command complains that it cannot resolve the lodash module when I use any of the following:

import _ from "lodash";
import _ = require("lodash");
import * as _ from "lodash";

Inside my 'tsconfig.json' file I have included the following things:

...

"target": "es6",
"sourceMap": true,
"module": "commonjs",
"moduleResolution": "node",

...

But despite this it's still not finding any of the modules that are installed using npm.

Am I missing something that is required to make TypeScript find these modules?

I realize that without a TypeScript definition file TypeScript is unable to provide additional type checks; however, surely these should just default to the any type right?

1 Answers
Related