node.js 构建:找不到“节点”的类型定义文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43542710/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:10:45  来源:igfitidea点击:

Build:Cannot find type definition file for 'node'

node.jsasp.net-mvcangular

提问by bitshift

VS 2015 community edition (at home), npm 3.10, Angular 2 Im trying to pull get Angular2 setup within an ASP.Net MVC 5 app. The template I started with used an older version of Angular, so I updated the package references.

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

When I build, the first error in the list is:
Build:Cannot find type definition file for 'node'
There are dozens of other errors after that but Im assuming most are due to this first issue.

当我构建时,列表中的第一个错误是:
Build:Cannot find type definition file for 'node' 之后
还有许多其他错误,但我假设大多数是由于第一个问题引起的。

Here is the package.json and typings.json

这是 package.json 和typings.json

package.json

包.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

打字.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"
  }
}

If I try to update just the typings, I get these messages

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

*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)*

[ update]
cleaning out my node_modules folder, then running npm install again cleared things up. This seems to happen most often when I move a project folder to another location on my system.

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

采纳答案by argoo

I had several problems updating packages through visual studio. From now i always update or add packages with the powershell console.

我在通过 Visual Studio 更新软件包时遇到了几个问题。从现在开始,我总是使用 powershell 控制台更新或添加软件包。

Start PowerShelland navigate to the folder where package.jsonis located and then run npm installRestart visual studio after the installation is done.

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

You can also try to delete your node_modulesfolder then run npm install

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

Hope this will solve your problems.

希望这能解决您的问题。

回答by M2012

In my case, I solved my problem. Hopefully it helps some else later.

就我而言,我解决了我的问题。希望以后能帮到其他人。

npm install @types/node --save-dev

回答by Simon_Weaver

For local Visual Studio

对于本地 Visual Studio

If you're starting with a clean template the build in VS functionality should probably work!

如果您从一个干净的模板开始,那么在 VS 中构建的功能应该可以工作!

Go to Dependencies> npm> Right Click > Restore Packages

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

Then try build again.

然后再次尝试构建。

For Visual Studio Team Services

对于 Visual Studio 团队服务

  • Install node https://nodejs.org/en/download/
  • Restart your agent service (VSTS Agent) if not using hosted agents
  • Add a build task to run npm install
  • Click the menu icon next to 'Working folder' to choose the location where your project.json file is located.

    enter code here

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

    在此处输入代码

回答by TARJU

Problem can be around other issues as well

问题也可能与其他问题有关

Try one of the step of the solution posted here Cannot find type definition file for 'node'by me

尝试此处发布的解决方案的步骤之一无法找到我的“节点”类型定义文件