danday74
danday74

Reputation: 56996

typescript installs lodash incorrectly

I've been installing lodash with ..

typings install dt~lodash --global --save

worked perfectly until recently but now i get ..

Attempted to compile "lodash" as a global module, but it looks like an external module. You'll need to remove the global option to continue.

so i did ..

typings install dt~lodash --save

which allowed the install to proceed.

But now in my logs I get the error ..

typings\modules\lodash\index.d.ts(243,1): error TS1316: Global module exports may only appear at top level.

that is a file generated by typings. line 243 looks like ..

export as namespace _;

Webstorm IDE also gives exactly the same error.

any idea how to fix this? thx

Upvotes: 3

Views: 1497

Answers (2)

Kloe2378231
Kloe2378231

Reputation: 1434

To force a previous version of the lodash ts definition file to be downloaded, both syntax works for me:

{
    "globalDependencies": {
        "lodash": "github:DefinitelyTyped/DefinitelyTyped/lodash/index.d.ts#253e456e3c0bf4bd34afaceb7dcbae282da14066",
    }
}

where 253e456e3c0bf4bd34afaceb7dcbae282da14066 is the commit hash code in github, or

{
    "globalDependencies": {
        "lodash": "registry:dt/lodash#4.14.0+20161110215204",
    }
}

where 4.14.0+20161110215204 is supposed to be a tagged version, but not sure how it is generated. I found it in the typings/globals/lodash/typings.json file of the last working downloaded .d.ts version.

Upvotes: 1

ranakrunal9
ranakrunal9

Reputation: 13558

You can install lodash as below also :

npm install --save @types/lodash

Then, in your .ts file:

Either:

import * as _ from "lodash";

Or

import _ from "lodash";

Upvotes: 2

Related Questions