TS2307 Build: Cannot find module lodash '

Update

I'm sorry, I didn't explain my problem very clearly. The errors I was getting were not when compiling my Angular app via Gulp, but in the Errors list of Visual Studio. Since then I have been able to resolve the issue (at least a workaround), but I would like to thank everyone who answered. My resolution is below.


I created an Angular4 / TypeScript app in a basic Asp.Net PoC web app. The Angular4 app worked fine in my PoC app, so I copied all the relevant files into the app I am developing (also the main Asp.Net web app).

Then I ran 'npm install' to make sure all dependencies were installed and used by Gulp to create .js files in my wwwroot / js / folder. Gulp finished without errors, but now Visual Studio reports below error and prevents me from building the project.

TS2307 Build:Cannot find module 'lodash'.

      

What's even more confusing is that after following the steps above, the original PoC application gets the same error despite no changes made to the project, which makes me think it's a more environmental issue.

I read Similar Issue , which says to install @ types / lodash but throws duplicate errors (removing ticks fixes duplicate errors but throws other errors).

Ts error code causing the error:

import * as _ from "lodash";

      

Go to:

import _ from "lodash";

      

does not work.

Thanks in advance for any help as I am currently tearing my hair out trying to figure out why this no longer works.

My config files look like this:

package.json

{
  "version": "1.0.0",
  "name": "aspnet",
  "private": true,
  "scripts": {
    "postinstall": "typings install",
    "typings": "typings"
  },
  "dependencies": {
    "@angular/common": "~4.0.0",
    "@angular/compiler": "~4.0.0",
    "@angular/core": "~4.0.0",
    "@angular/forms": "~4.0.0",
    "@angular/http": "~4.0.0",
    "@angular/platform-browser": "~4.0.0",
    "@angular/platform-browser-dynamic": "~4.0.0",
    "@angular/router": "~4.0.0",
    "angular-in-memory-web-api": "~0.3.0",
    "angular2-datatable": "^0.6.0",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "lodash": "^4.17.4",
    "moment": "^2.14.1",
    "reflect-metadata": "^0.1.3",
    "rxjs": "5.0.1",
    "systemjs": "0.19.40",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@types/node": "7.0.7",
    "gulp": "^3.9.1",
    "gulp-clean": "^0.3.2",
    "gulp-concat": "^2.6.1",
    "gulp-less": "^3.1.0",
    "gulp-sourcemaps": "^1.6.0",
    "gulp-tsc": "^1.3.1",
    "gulp-typescript": "^3.1.6",
    "gulp-uglify": "^2.0.0",
    "path": "^0.12.7",
    "typescript": "^2.1.0",
    "typings": "^2.1.0"
  }
}
      

Run codeHide result


typings.json

    {
  "globalDependencies": {
    "core-js": "registry:dt/core-js#0.0.0+20160725163759",
    "jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
    "node": "registry:dt/node#6.0.0+20160909174046"
  }
}
      

Run codeHide result


tsconfig.json

    {
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "module": "commonjs",
    "noEmitOnError": true,
    "noImplicitAny": false,
    "outDir": "../wwwroot/app/",
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "moduleResolution": "node",
    "typeRoots": [
      "./node_modules/@types",
      "./node_modules"
    ],
    "types": [
      "node"
    ]
  },
  "exclude": [
    "node_modules"
  ]
}
      

Run codeHide result


+3


source to share


2 answers


Thanks again to everyone who responded and I apologize for not being clearer with the actual issue initially.

My TypeScript files were compiling correctly, but Visual Studio continued to report build failures in the Error List window.



After following a few steps (listed above, many others), this issue was fixed: http://rostacik.net/2015/08/14/how-to-disable-building-of-typescript-files-in -visual-studio-2015 /

In short, open the .xproj project file (maybe ".csproj") with a text editor. Find tags <PropertyGroup> </PropertyGroup>

and add a line <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>

. Save the file, and then allow Visual Studio to update the files as needed. Now re-create the application.

0


source


You have to install @types/lodash

package with:

npm install --save @types/lodash

      

This will tell the Typescript compiler what lodash is and what modules and components are exposed by the library.

It is also typings

no longer recommended. You should uninstall and uninstall typings

and you should only switch to packages @types

by updating your tsconfig to:



"typeRoots": [
  "node_modules/@types"
],

      

Finally, once you've removed the typing, you need to add @types

packages for core-js

and jasmine

in order to include those packages:

npm install --save @types/core-js
npm install --save @types/jasmine

      

+2


source







All Articles