Angular4-npm jQuery错误TS1005:','预期 [英] Angular4 - npm jQuery error TS1005: ',' expected

查看:69
本文介绍了Angular4-npm jQuery错误TS1005:','预期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在通过以下方式安装jquery软件包之前,我的项目正常:

My project was ok until moment I installed jquery packages via:

npm install jquery

和:

npm install -D @types/jquery

此后,我遇到了一些错误,并决定通过索引文件中的脚本标签使用jQuery.因此尝试卸载已安装的软件包:

After this I got some errors and decided to use jQuery via script tags in index file. So tried to uninstall installed packages:

npm uninstall jquery
npm uninstall @types/jquery

还尝试使用sudo和/或--save和/或--save-dev,例如:

Also tried with sudo and/or --save and/or --save-dev like:

sudo npm uninstall jquery --save-dev

根据控制台,安装进度进展顺利:

Uninstalation progress went well, according to the console:

在2.199秒内删除了1个程序包

removed 1 package in 2.199s

但是尝试npm start时我仍然收到错误:

But I still received error while tried to npm start:

node_modules/@types/jquery/index.d.ts(47,40):错误TS1005:',' 预期的. node_modules/@types/jquery/index.d.ts(2370,40):错误 TS1005:,"应为. node_modules/@types/jquery/index.d.ts(2372,46): 错误TS1005:,"预期. node_modules/@types/jquery/index.d.ts(2483,23):错误TS1005:',' 预期的. 等等...

node_modules/@types/jquery/index.d.ts(47,40): error TS1005: ',' expected. node_modules/@types/jquery/index.d.ts(2370,40): error TS1005: ',' expected. node_modules/@types/jquery/index.d.ts(2372,46): error TS1005: ',' expected. node_modules/@types/jquery/index.d.ts(2483,23): error TS1005: ',' expected. and so forth...

然后注意到nodemodules/@types仍然包含jquery,因此我手动将其删除,但是随后:

Then noticed that nodemodules/@types still contains jquery so I deleted it manually, but then:

node_modules/@types/angular-animate/index.d.ts(6,1):错误TS2688: 找不到"jquery"的类型定义文件. node_modules/@types/angular/index.d.ts(6,1):错误TS2688:找不到 'jquery'的类型定义文件. node_modules/@types/angular/index.d.ts(86,18):错误TS2304:无法 找到名称"JQueryStatic". node_modules/@types/angular/index.d.ts(2004,46):错误TS2304:无法 找到名称"JQueryStatic". src/app/search.component.ts(14,19):错误 TS2339:类型"{}"上不存在属性目标". npm ERR!代码 ELIFECYCLE npm ERR! errno 2 npm错误! angular-tut@1.0.0生成:tsc -p src/ npm ERR!退出状态2

node_modules/@types/angular-animate/index.d.ts(6,1): error TS2688: Cannot find type definition file for 'jquery'. node_modules/@types/angular/index.d.ts(6,1): error TS2688: Cannot find type definition file for 'jquery'. node_modules/@types/angular/index.d.ts(86,18): error TS2304: Cannot find name 'JQueryStatic'. node_modules/@types/angular/index.d.ts(2004,46): error TS2304: Cannot find name 'JQueryStatic'. src/app/search.component.ts(14,19): error TS2339: Property 'target' does not exist on type '{}'. npm ERR! code ELIFECYCLE npm ERR! errno 2 npm ERR! angular-tut@1.0.0 build: tsc -p src/ npm ERR! Exit status 2

据我了解,在安装jQuery之后,我还更改了其他node_modules(@ types/angular)吗?

So as I understand after I installed jQuery, I also changed other node_modules (@types/angular) ?

更新:

按照@selemmn的建议,我试图删除渔获物:

As @selemmn recommended I tried to delete catch:

rm -r node_modules

npm cache clean在此之后:

npm ERR!从npm @ 5开始,npm缓存会因损坏问题而自我修复 并且保证从缓存中提取的数据是有效的.如果你 要确保所有内容都一致,请使用"npm缓存验证" 反而. npm ERR! npm ERR!如果您确定要删除 整个缓存,请使用--force重新运行此命令.

npm ERR! As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead. npm ERR! npm ERR! If you're sure you want to delete the entire cache, rerun this command with --force.

所以:

npm cache clean --force

npm install

并收到此错误:

node-pre-gyp ERR!堆栈TypeError:无法读取的属性版本" 空

node-pre-gyp ERR! stack TypeError: Cannot read property 'version' of null

因此,从 gitHub 中,删除了package-lock.json和再次删除软件包和缓存.

So as from gitHub, remvoved package-lock.json and again removed packages and cache.

现在尝试npm start将我带到起点:

And now trying npm start brought me to the starting point:

node_modules/@types/jquery/index.d.ts(47,40):错误TS1005:',' 预期的. node_modules/@types/jquery/index.d.ts(2370,40):错误 TS1005:,"应为. node_modules/@types/jquery/index.d.ts(2372,46): 错误TS1005:,"预期. node_modules/@types/jquery/index.d.ts(2483,23):错误TS1005:',' 预期的. node_modules/@types/jquery/index.d.ts(2484,17):错误 TS1005:,"应为. node_modules/@types/jquery/index.d.ts(2485,17): 错误TS1005:,"预期.等等

node_modules/@types/jquery/index.d.ts(47,40): error TS1005: ',' expected. node_modules/@types/jquery/index.d.ts(2370,40): error TS1005: ',' expected. node_modules/@types/jquery/index.d.ts(2372,46): error TS1005: ',' expected. node_modules/@types/jquery/index.d.ts(2483,23): error TS1005: ',' expected. node_modules/@types/jquery/index.d.ts(2484,17): error TS1005: ',' expected. node_modules/@types/jquery/index.d.ts(2485,17): error TS1005: ',' expected. and so forth

package.json:

package.json:

{
  "name": "angular-tut",
  "version": "1.0.0",
  "private": true,
  "description": "Example project from an angular.io guide.",
  "scripts": {
    "test:once": "karma start karma.conf.js --single-run",
    "build": "tsc -p src/",
    "serve": "lite-server -c=bs-config.json",
    "prestart": "npm run build",
    "start": "concurrently \"npm run build:watch\" \"npm run serve\"",
    "pretest": "npm run build",
    "test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"",
    "pretest:once": "npm run build",
    "build:watch": "tsc -p src/ -w",
    "build:upgrade": "tsc",
    "serve:upgrade": "http-server",
    "build:aot": "ngc -p tsconfig-aot.json && rollup -c rollup-config.js",
    "serve:aot": "lite-server -c bs-config.aot.json",
    "build:babel": "babel src -d src --extensions \".es6\" --source-maps",
    "copy-dist-files": "node ./copy-dist-files.js",
    "i18n": "ng-xi18n",
    "lint": "tslint ./src/**/*.ts -t verbose"
  },
  "keywords": [],
  "author": "",
  "license": "MIT",
  "dependencies": {
    "@angular/animations": "4.0.3",
    "@angular/common": "~4.0.0",
    "@angular/compiler": "~4.0.0",
    "@angular/compiler-cli": "~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/platform-server": "~4.0.0",
    "@angular/router": "~4.0.0",
    "@angular/tsc-wrapped": "~4.0.0",
    "@angular/upgrade": "~4.0.0",
    "@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.26",
    "angular-in-memory-web-api": "~0.3.1",
    "core-js": "^2.4.1",
    "rxjs": "5.0.1",
    "systemjs": "0.19.39",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@types/angular": "^1.6.20",
    "@types/angular-animate": "^1.5.7",
    "@types/angular-cookies": "^1.4.4",
    "@types/angular-mocks": "^1.5.10",
    "@types/angular-resource": "^1.5.9",
    "@types/angular-route": "^1.3.4",
    "@types/angular-sanitize": "^1.3.5",
    "@types/jasmine": "2.5.36",
    "@types/node": "^6.0.45",
    "babel-cli": "^6.16.0",
    "babel-preset-angular2": "^0.0.2",
    "babel-preset-es2015": "^6.16.0",
    "canonical-path": "0.0.2",
    "concurrently": "^3.0.0",
    "http-server": "^0.9.0",
    "jasmine": "~2.4.1",
    "jasmine-core": "~2.4.1",
    "karma": "^1.3.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "karma-phantomjs-launcher": "^1.0.2",
    "lite-server": "^2.2.2",
    "lodash": "^4.16.2",
    "phantomjs-prebuilt": "^2.1.7",
    "protractor": "~4.0.14",
    "rollup": "^0.41.6",
    "rollup-plugin-commonjs": "^8.0.2",
    "rollup-plugin-node-resolve": "2.0.0",
    "rollup-plugin-uglify": "^1.0.1",
    "source-map-explorer": "^1.3.2",
    "tslint": "^3.15.1",
    "typescript": "~2.2.0"
  },
  "repository": {}
}

更新2:

我不明白-我删除了所有软件包-rm -r node_modules.还要删除paskage-lock.json并进行缓存,如果我尝试在整个项目中搜索"jquery",则找不到任何内容,但是在运行npm install之后,使用以下命令创建的package-lock.json文件:

I dont get it - I delete all packages - rm -r node_modules. Also delete paskage-lock.json and cache as well and if I try to search for "jquery" in the whole project, nothing is found, but after I run npm install, package-lock.json file being created with:

"@types/jquery": {
  "version": "3.2.3",
  "resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-3.2.3.tgz",
  "integrity": "sha512-3/ETl4JziXnuFIx6W+WB7BzPGRnYH2O/AFKafSOulabMyAhRfv/oboEO2yytsRvzZDiLFODuydYbr7C0kudB9w==",
  "dev": true
},

那么这个jQuery是从哪里来的?

So where this jQuery is coming from??

推荐答案

我通过将以下内容添加到package.json中来修复了相同的错误

I've fixed the same error by adding belows to my package.json

"devDependencies": {
...
"@types/jquery": "^2.0.42",
...
}

感谢您的UPDATE2,所以我可以找到这个@ types/jquery lib

Thanks for your UPDATE2, so can I find this @types/jquery lib

这篇关于Angular4-npm jQuery错误TS1005:','预期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆