Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lodash - '_' refers to a UMD global and lodash.js is not a module errors

If I do nothing and add the type definition it works for jquery but lodash gets a

'_' referes to a UMD global, but the current file is a module. Consider adding an import instead.

If I try to import lodash with any combination of import call, I get

lodash.js is not a module

I tried to get help by asking a question here and it was closed because there was another answer for Angular (Angular 2). I really need a real answer so I'm re-posting with my own solutions, hoping someone will eventually help me understand this problem.

In this case I am:

  1. Not using any frameworks like Angular
  2. Using TypeScript
  3. Using requirejs to import modules
  4. Using Visual Studio
  5. Using MVC5
like image 964
AndrewBenjamin Avatar asked Nov 28 '17 23:11

AndrewBenjamin


2 Answers

I use import * as _ from 'lodash'; in my working file after installing lodash.

like image 117
Nizam Khan Avatar answered Sep 18 '22 09:09

Nizam Khan


I added following code in my global typing definition file (~\src\typings.d.ts) to fix the problem. I'm using Angular CLI 1.7

// lodash global typing - begin
declare namespace _ {
}
// lodash global typing - end
like image 36
Feng Avatar answered Sep 17 '22 09:09

Feng