Search code examples
typescriptasp.net-mvc-5requirejslodash

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

Solution

  • 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