簡體   English   中英

構建:找不到“節點”的類型定義文件

[英]Build:Cannot find type definition file for 'node'

VS 2015 社區版(在家)、npm 3.10、Angular 2 我試圖在 ASP.Net MVC 5 應用程序中拉取 Angular2 設置。 我開始使用的模板使用了舊版本的 Angular,所以我更新了包引用。

當我構建時,列表中的第一個錯誤是:
構建:找不到“節點”的類型定義文件
之后還有許多其他錯誤,但我假設大多數是由於第一個問題造成的。

這是 package.json 和typings.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"
  }
}

打字.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 清除一切。 當我將項目文件夾移動到系統上的另一個位置時,這似乎最常發生。

就我而言,我解決了我的問題。 希望以后能對其他人有所幫助。

npm install @types/node --save-dev

我在通過Visual Studio更新軟件包時遇到了一些問題。 從現在開始,我始終使用Powershell控制台更新或添加軟件包。

啟動PowerShell並導航到package.json所在的文件夾,然后運行npm install完成安裝后重新啟動visual studio。

您也可以嘗試刪除您的node_modules文件夾,然后運行npm install

希望這能解決您的問題。

重新啟動或重新加載我的 VSCode 工作

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

對於本地Visual Studio

如果您從一個干凈的模板開始,則VS功能中的內置功能應該可以工作!

轉到Dependencies > npm >右鍵單擊> Restore Packages

然后嘗試再次構建。

對於Visual Studio Team Services

  • 安裝節點https://nodejs.org/en/download/
  • 如果不使用托管代理,請重新啟動代理服務(VSTS代理)
  • 添加構建任務以運行npm install
  • 單擊“工作文件夾”旁邊的菜單圖標,選擇project.json文件所在的位置。

    在這里輸入代碼

有時只是因為缺少某些軟件包。 您可以嘗試運行yarn installnpm install應該可以解決。

問題也可能與其他問題有關

嘗試此處發布的解決方案的步驟之一無法找到我的“節點”類型定義文件

我在使用 RN 時遇到了這個問題,並且我對我的包的依賴不正確。

    "@types/": "react-navigation/native",

反應導航/本機不存在

json 在此處輸入圖片說明

當我嘗試用它運行 tsc 時,我得到了這個

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM