简体   繁体   中英

Cannot find type definition file for 'node'

I am getting strange errors after updating angular, webpack and typescript. Any idea what I could be missing?

When I run the app with npm start I get the following errors:

[at-loader] Cannot find type definition file for 'hammerjs'.
[at-loader] Cannot find type definition file for 'node'.
[at-loader] src\app\app.component.ts:26:14
Cannot find name 'require'.
[at-loader] src\app\app.component.ts:30:15
Cannot find name 'require'.

Here are the dependencies:

"dependencies": {
"@angular/common": "2.4.4",
"@angular/compiler": "2.4.4",
"@angular/core": "2.4.4",
"@angular/forms": "2.4.4",
"@angular/http": "2.4.4",
"@angular/material": "2.0.0-beta.1",
"@angular/platform-browser": "2.4.4",
"@angular/platform-browser-dynamic": "2.4.4",
"@angular/platform-server": "2.4.4",
"@angular/router": "3.4.4",
"@angularclass/conventions-loader": "^1.0.13",
"@angularclass/hmr": "~1.2.2",
"@angularclass/hmr-loader": "~3.0.2",
"@ng-bootstrap/ng-bootstrap": "1.0.0-alpha.18",
"angular2-jwt": "0.1.28",
"angular2-moment": "1.1.0",
"auth0-lock": "10.10.1",
"bootstrap": "4.0.0-alpha.5",
"cky-meta": "^1.0.2",
"core-js": "^2.4.1",
"hammerjs": "2.0.8",
"http-server": "^0.9.0",
"ie-shim": "^0.1.0",
"intl": "^1.2.5",
"ng2-img-cropper": "0.7.7",
"ng2-page-scroll": "3.2.1",
"ng2-sharebuttons": "1.1.5",
"reflect-metadata": "^0.1.9",
"rxjs": "5.0.3",
"web-animations-js": "2.2.2",
"zone.js": "0.7.6"
   },
      "devDependencies": {
"@angular/compiler-cli": "~2.4.4",
"@types/chai": "3.4.34",
"@types/core-js": "^0.9.35",
"@types/es6-shim": "^0.31.32",
"@types/hammerjs": "^2.0.33",
"@types/jasmine": "^2.5.41",
"@types/node": "^6.0.60",
"@types/protractor": "^4.0.0",
"@types/selenium-webdriver": "2.53.39",
"@types/source-map": "^0.5.0",
"@types/uglify-js": "^2.0.27",
"@types/webpack": "^2.2.2",
"add-asset-html-webpack-plugin": "^1.0.2",
"angular-router-loader": "^0.5.0",
"angular2-template-loader": "^0.6.0",
"assets-webpack-plugin": "^3.5.1",
"awesome-typescript-loader": "~3.0.0-beta.18",
"bootstrap-loader": "2.0.0-beta.19",
"codelyzer": "~2.0.0-beta.4",
"copy-webpack-plugin": "^4.0.0",
"css-loader": "^0.26.0",
"exports-loader": "^0.6.3",
"expose-loader": "^0.7.1",
"file-loader": "^0.9.0",
"gh-pages": "^0.12.0",
"html-webpack-plugin": "^2.26.0",
"imports-loader": "^0.7.0",
"istanbul-instrumenter-loader": "1.2.0",
"jasmine-core": "^2.5.2",
"json-loader": "^0.5.4",
"karma": "^1.4.0",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.0.2",
"karma-mocha-reporter": "^2.2.2",
"karma-remap-coverage": "^0.1.4",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "2.0.1",
"ng2-facebook-sdk": "1.2.0",
"ngc-webpack": "^1.1.2",
"node-sass": "4.3.0",
"npm-run-all": "^4.0.1",
"parse5": "^3.0.1",
"postcss-loader": "1.2.2",
"protractor": "^4.0.14",
"raw-loader": "0.5.1",
"resolve-url-loader": "1.6.1",
"rimraf": "~2.5.4",
"sass-loader": "4.1.1",
"script-ext-html-webpack-plugin": "^1.5.0",
"source-map-loader": "^0.1.6",
"string-replace-loader": "^1.0.5",
"style-loader": "^0.13.1",
"to-string-loader": "^1.1.5",
"ts-helpers": "1.1.2",
"ts-node": "^2.0.0",
"tslint": "4.3.1",
"typedoc": "^0.5.5",
"typescript": "2.1.5",
"typings": "2.1.0",
"url-loader": "^0.5.7",
"v8-lazy-parse-webpack-plugin": "^0.3.0",
"webpack": "2.2.0",
"webpack-dev-middleware": "^1.9.0",
"webpack-dev-server": "2.2.0",
"webpack-dll-bundles-plugin": "^1.0.0-beta.5",
"webpack-md5-hash": "^0.0.5",
"webpack-merge": "~2.4.0"

}, "engines": { "node": ">= 4.2.1", "npm": ">= 3" }

Try re-importing the @types/node package by running this in the Package Manager Console in Visual Studio:

npm i -D @types/node

If a specific version must be used, you can specify:

npm i -D @types/node@6.0.10

That seems more likely to be a problem of versions within the typings.json file. Can you try the following?

typings install dt~node --save
typings install dt~core-js --save
typings install dt~hammerjs --save

It could either be a mismatched ts-node version in which updating ts-node should fix it found here or it could be an incorrect tsconfig.json found here

If these don't work here are some links you may find useful:

https://github.com/shlomiassaf/angular2-modal/issues/213

VS2015: "Cannot find type definition" and "File not found" errors

In my case, after doing an npm update I was getting this error. It disappeared by restarting my node server :

npm start

You might need to apply multiple solutions to solve this issue!

STEP 1

You might need to install missing typings from @types it's already present and still you are getting this error proceed to step 2

STEP 2

If you are using ts-loader you will need to upgrade this

STEP 3 (Not applicable to all)

In some cases it's the webpack versioning which causes this error; upgrading to webpack version, ts-node, awesome-typescript-loader etc will solve it for you

STEP 4 (Angular only)

If you have used core-js upgrade its version

In general solution varies for all however its the node modules version where you will need to play around a bit! It's more of hit and try

All the best!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM