【发布时间】:2017-09-17 11:51:54
【问题描述】:
更新
抱歉,我没有很清楚地解释我的问题。我得到的错误不是在通过 Gulp 编译 Angular 应用程序时,而是在 Visual Studio 的“错误列表”中。我已经能够解决这个问题(至少是解决方法),但我要感谢所有回复的人。我的分辨率如下。
我在 PoC Asp.Net Core Web 应用程序中构建了一个 Angular4 / TypeScript 应用程序。 Angular4 应用程序在我的 PoC 应用程序中运行良好,因此我将所有相关文件复制到我正在开发的应用程序(也是一个 Asp.Net Core Web 应用程序)中。
然后我运行“npm install”以确保所有依赖项都已安装并使用 Gulp 在我的 wwwroot/js/ 文件夹中创建 .js 文件。 Gulp 没有错误地完成,但现在 Visual Studio 报告了以下错误并阻止我构建项目。
TS2307 Build:Cannot find module 'lodash'.
更令人困惑的是,在完成上述步骤后,原始 PoC 应用程序出现了同样的错误,尽管项目没有进行任何更改,这让我认为这更像是一个环境问题。
我已经阅读了Similar Issue,他们说要安装@types/lodash,但这会导致重复错误(卸载打字可以修复重复错误,但会导致其他错误)。
抛出错误的.ts代码是:
import * as _ from "lodash";
改为:
import _ from "lodash";
不工作。
提前感谢您提供的任何帮助,因为我目前正忙着想弄清楚为什么这不再起作用了。
我的配置文件如下:
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"
}
}
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"
}
}
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"
]
}
【问题讨论】:
标签: angular typescript visual-studio-2015 npm-install