Definitelytyped: @types/lodash Module has no exported member

Created on 9 May 2018  ยท  11Comments  ยท  Source: DefinitelyTyped/DefinitelyTyped

Recently I've started getting errors like Module '".../@types/lodash/index"' has no exported member
for the methods that are definitely there, like map, filter, find, each, includes, etc...

Same error also happens for the import { map } from 'lodash/map'

@bczengel @chrootsu @stepancar @aj-r @ailrun @e-cloud @thorn0 @jtmthf @DomiR

Most helpful comment

You need to enable esModuleInterop, or do import * as map ...

The bulk import you describe should also work. Does it not?

On Wed, May 9, 2018, 3:09 PM Vasili Sviridov, notifications@github.com
wrote:

Usually I just import them in bulk with import { map, filter } from
'lodash'

โ€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/DefinitelyTyped/DefinitelyTyped/issues/25659#issuecomment-387844148,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGpes-2QtCIkixLZWzNgPbvNSTWfDcrZks5twz7YgaJpZM4T40SJ
.

All 11 comments

You should import like this:

import map from "lodash/map";

No braces.

On Wed, May 9, 2018, 2:50 PM Vasili Sviridov, notifications@github.com
wrote:

Recently I've started getting errors like Module
'".../@types/lodash/index"' has no exported member
for the methods that are definitely there, like map, filter, find, each,
includes, etc...

Same error also happens for the import { map } from 'lodash/map'

@bczengel https://github.com/bczengel @chrootsu
https://github.com/chrootsu @stepancar https://github.com/stepancar
@aj-r https://github.com/aj-r @Ailrun https://github.com/Ailrun
@e-cloud https://github.com/e-cloud @thorn0 https://github.com/thorn0
@jtmthf https://github.com/jtmthf @DomiR https://github.com/DomiR

โ€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/DefinitelyTyped/DefinitelyTyped/issues/25659, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AGpes6E0NDy7d9aMCTBIVeCL3KJlM-Jaks5twzqLgaJpZM4T40SJ
.

Then I get 'Module has no default export'

Usually I just import them in bulk with import { map, filter } from 'lodash'

You need to enable esModuleInterop, or do import * as map ...

The bulk import you describe should also work. Does it not?

On Wed, May 9, 2018, 3:09 PM Vasili Sviridov, notifications@github.com
wrote:

Usually I just import them in bulk with import { map, filter } from
'lodash'

โ€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/DefinitelyTyped/DefinitelyTyped/issues/25659#issuecomment-387844148,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGpes-2QtCIkixLZWzNgPbvNSTWfDcrZks5twz7YgaJpZM4T40SJ
.

image
It works for some, but not others

@vsviridov I cannot reproduce this issue. Can you give your:

  • typescript version
  • @types/lodash version
  • tsconfig.json

Just to bump this issue, I've just installed @types/lodash and I'm getting the following compilation error, repeated for each module I've included.

TS2497: Module '"./node_modules/@types/lodash/assign"' resolves to a non-module entity and cannot be imported using this construct.

Source:

import * as first from 'lodash/first'
import * as keys from 'lodash/keys'
import * as map from 'lodash/map'
import * as reduce from 'lodash/reduce'
import * as sortBy from 'lodash/sortBy'
import * as truncate from 'lodash/truncate'
import * as values from 'lodash/values'

Prior to installing the types this code compiled fine (and so I will be uninstalling the types package)

Since @vsviridov has not provided you with the versions, I hope mine are helpful:

โžœ  npm list --depth=0 typescript @types/lodash lodash
[email protected] .
...
โ”œโ”€โ”€ @types/[email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
...
โžœ  cat ./tsconfig.json
{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "jsx": "react",
    "types": [
      "webpack-env",
      "node"
    ],
    "allowJs": true,
    "lib": [
      "DOM",
      "ES5",
      "ScriptHost",
      "es2015"
    ]
  },
  "include": [
    "./src/**/*"
  ]
}

I include each module separately to avoid bundling the entire lodash library when I only need a handful of the utilities

Ah, I've never used awesome-typescript-loader before. I will try it.

You could try setting "esModuleInterop": true in your tsconfig, then import like this:

import assign from "lodash/assign";

Or you could try using lodash-es (and @types/lodash-es), which uses proper es6 modules and should support tree shaking.

I have an error:
4,31): Module '"/Users/apavlov/Sites/webend/node_modules/@types/lodash-es/index"' has no exported member 'chain'

I import this like this import { groupBy, keyBy, get, chain, times, isEmpty } from 'lodash-es';
As told @vsviridov it works for some, but for some, it does not http://take.ms/3LJPZ

After a small investigation, I see that there is really no appropriate type for this method here

lodash-es requires webpack 4.. what about webpack 3? I'm getting this error
Module '"c:/laragon/www/planmymedia/node_modules/@types/lodash/uniqBy"' has no default export.
when i'm using this import uniqBy from 'lodash/uniqBy';

Re: @valentinoPereira : I'm not sure what you mean by "lodash-es requires webpack 4". lodash-es has no dependencies, and should work with any version of webpack.

The import you show uses lodash, not lodash-es. You should do import uniqBy from 'lodash-es/uniqBy'; (or import {uniqBy} from 'lodash-es'; if you're using tree shaking). Or, if you want to use plain lodash instead of lodash-es, then turn on esModuleInterop as I mentioned in an earlier comment.

Re: @a-pavlov-parc : chaining does not work well in lodash-es: (see https://github.com/lodash/lodash/issues/3298). You might want to consider another approach, like using lodash/fp with lodah's flow function as described here.

Note that you can't use lodash-es with the fp approach, so if you want tree shaking, you'll have to do it manually by importing each function from a separate file like this:

import map from "lodash/fp/map";
import flow from "lodash/fp/flow";
// etc.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

csharpner picture csharpner  ยท  3Comments

jgoz picture jgoz  ยท  3Comments

ArtemZag picture ArtemZag  ยท  3Comments

alisabzevari picture alisabzevari  ยท  3Comments

fasatrix picture fasatrix  ยท  3Comments