更新angular,webpack和打字稿后,我遇到了奇怪的错误。 知道我可能缺少什么吗?
当我使用npm start运行应用程序时,出现以下错误:
[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'.
以下是依赖项:
"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"
}, “引擎”: { “node”:“> = 4.2.1”, “npm”:“> = 3” }
答案 0 :(得分:0)
这似乎更可能是typings.json
文件中的版本问题。你能试试以下吗?
typings install dt~node --save
typings install dt~core-js --save
typings install dt~hammerjs --save
答案 1 :(得分:0)
它可能是一个不匹配的ts节点版本,其中更新ts节点应该修复它found here或者它可能是不正确的tsconfig.json found here
如果这些不起作用,您可能会发现一些有用的链接:
https://github.com/shlomiassaf/angular2-modal/issues/213
VS2015: "Cannot find type definition" and "File not found" errors
答案 2 :(得分:0)
尝试在Visual Studio的“程序包管理器”控制台中运行@ types / node程序包,以重新导入它:
npm i -D @types/node
如果必须使用特定版本,则可以指定:
npm i -D @types/node@6.0.10
答案 3 :(得分:0)
就我而言,在执行npm更新后,出现此错误。通过重新启动我的节点服务器,它消失了:
npm start
答案 4 :(得分:0)
您可能需要从@types安装缺少的类型 它已经存在,但仍然出现此错误,请继续执行步骤2
如果您使用的是ts-loader,则需要对其进行升级
在某些情况下,是Webpack版本控制导致此错误;升级到Webpack版本,ts-node,awesome-typescript-loader等将为您解决
如果您已使用core-js升级其版本
通常,所有解决方案都各不相同,但是它的节点模块版本需要您多花一点时间!尝试更多
祝一切顺利!