构建:找不到'node'的类型定义文件

时间:2017-04-21 12:26:11

标签: node.js asp.net-mvc angular

VS 2015社区版(在家),npm 3.10,Angular 2 我试图在ASP.Net MVC 5应用程序中获取Angular2设置。我开始使用的模板使用了旧版本的Angular,因此我更新了包引用。

当我构建时,列表中的第一个错误是:
Build:找不到'node'的类型定义文件
之后还有其他几十个错误,但我假设大多数是由于第一个问题。

这是package.json和typings.json

的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",
    "systemjs": "0.19.40",
    "core-js": "^2.4.1",
    "rxjs": "5.0.1",
    "zone.js": "^0.8.4",
    "bootstrap": "^3.3.7"
  },
  "devDependencies": {
    "@types/core-js": "^0.9.41",
    "gulp": "^3.9.1",
    "gulp-clean": "^0.3.2",
    "gulp-concat": "^2.6.1",
    "gulp-tsc": "^1.3.1",
    "gulp-typescript": "^3.1.6",
    "path": "^0.12.7",
    "typescript": "~2.1.0",
    "typings": "~2.1.1"
  }
}

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"
  }
}

如果我尝试仅更新打字,我会收到这些消息

*typings WARN deprecated 11/21/2016: "registry:dt/node#6.0.0+20160909174046" is deprecated (updated, replaced or removed)
typings WARN deprecated 9/14/2016: "registry:dt/core-js#0.0.0+20160725163759" is deprecated (updated, replaced or removed)
typings WARN deprecated 10/25/2016: "registry:dt/jasmine#2.2.0+20160621224255" is deprecated (updated, replaced or removed)*

[更新]
清理我的node_modules文件夹,然后再次运行npm install清除了一切。当我将项目文件夹移动到系统上的另一个位置时,这似乎最常发生。

7 个答案:

答案 0 :(得分:35)

就我而言,我解决了我的问题。希望以后能有所帮助。

npm install @types/node --save

答案 1 :(得分:8)

我通过visual studio更新包有几个问题。从现在开始,我总是使用powershell控制台更新或添加软件包。

启动PowerShell并导航到package.json所在的文件夹,然后运行npm install安装完成后重新启动visual studio。

您还可以尝试删除node_modules文件夹,然后运行npm install

希望这能解决你的问题。

答案 2 :(得分:1)

对于本地Visual Studio

如果您从一个干净的模板开始,VS功能的构建可能会起作用!

转到Dependencies> npm>右键单击> Restore Packages

然后再次尝试构建。

对于Visual Studio Team Services

  • 安装节点https://nodejs.org/en/download/
  • 如果未使用托管代理,则重新启动代理服务(VSTS代理)
  • 添加构建任务以运行npm install
  • 点击'工作文件夹'旁边的菜单图标选择project.json文件所在的位置。

    enter code here

答案 3 :(得分:1)

有时只是因为缺少某些软件包。您可以尝试运行 yarn installnpm install 应该可以解决。

答案 4 :(得分:0)

问题也可能围绕其他问题

尝试由我在这里Cannot find type definition file for 'node'发布的解决方案之一

答案 5 :(得分:0)

在 vscode 中解决这个问题的最简单方法是。

创建一个 .vscode 目录,然后在其中创建 settings.json 并放入下面的 json 就可以了。

{
"search.exclude": {
  "**/node_modules": true
},
"files.watcherExclude": {
  "**/.git/objects/**": true,
  "**/.git/subtree-cache/**": true,
  "**/node_modules/**": true,
  "env-*": true
},
"files.exclude": {
  "**/.git": true,
  "**/.DS_Store": true,
  "**/node_modules": true,
  "env*": true
}
}

答案 6 :(得分:0)

重新启动或重新加载我的 VSCode 工作