1

I'm using lodash with the new [email protected] project template, which includes

  • Typescript
  • Rollup
  • es2015 modules

This works for me:

npm install lodash --save
npm install @types/lodash --save-dev --save-exact
// typescript
import _ from "lodash";

But apparently lodash-es is recommended with Rollup because of the tree-shaking thing. But when I do this:

npm install lodash-es --save  // instead of `lodash`
npm install @types/lodash --save-dev --save-exact
// typescript
import _ from "lodash-es";

I get a Typescript error

error TS2307: Cannot find module 'lodash-es'.

However, the transpiled javascript actually works and runs correctly. What gives?

here is my tsconfig

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es2015"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "pretty": true,
    "target": "es5"
  },
  "filesGlob": [
    "**/*.ts",
    "!node_modules/**/*"
  ],
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

1 Answer 1

2

The problem is that no one has created a typings file for lodash-es so the Typescript compiler can't validate.

Sign up to request clarification or add additional context in comments.

3 Comments

We've made the typescript team aware, but frankly, it's really up to the community.
@icfantv can you link up here the issue where your entry is concerning this
@ESturzenegger, this was at an on-site meeting with a couple of members of the MSFT TS team. they took notes, but this isn't a TS issue, per se, rather a lodash and lodash community one: github.com/lodash/lodash/issues/1835.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.