首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular4 - npm jQuery错误TS1005:',‘预期

Angular4 - npm jQuery错误TS1005:',‘预期
EN

Stack Overflow用户
提问于 2017-06-21 09:26:52
回答 2查看 11.4K关注 0票数 8

我的项目一直正常,直到我通过以下方式安装了jquery包:

代码语言:javascript
复制
npm install jquery

以及:

代码语言:javascript
复制
npm install -D @types/jquery

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

代码语言:javascript
复制
npm uninstall jquery
npm uninstall @types/jquery

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

代码语言:javascript
复制
sudo npm uninstall jquery --save-dev

据控制台称,分期付款进展顺利:

移走2.199s中的1个包件

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

node_node/@type/jquery/index.d.ts(47,40):error 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:',‘预期。等等..。

然后注意到nodemodules/@types仍然包含jquery,所以我手动删除了它,但随后:

node_modules/@types/angular-animate/index.d.ts(6,1):error TS2688:无法找到“jquery”的类型定义文件。节点_模块/@类型/角/index.d.ts(6,1):错误TS2688:无法找到“jquery”的类型定义文件。node_modules/@types/angular/index.d.ts(86,18):error TS2304:无法找到名称“JQueryStatic”。node_modules/@types/angular/index.d.ts(2004,46):error TS2304:无法找到名称“JQueryStatic”。src/app/search.component.ts(14,19):error TS2339: Property 'target‘在类型{}上不存在。国家预防机制错误!代码ELIFECYCLE npm错误!错误的2 npm错误!构建:tsc -p src/ npm ERR!退出状态2

因此,正如我在安装jQuery之后所理解的那样,我还更改了其他node_modules (@node_modules/ changed )?

更新:

正如@selemmn建议的那样,我尝试删除catch:

rm -r node_modules

在此之后,npm cache clean得到:

国家预防机制错误!从npm@5开始,npm缓存自修复腐败问题,从缓存中提取的数据保证是有效的。如果要确保所有内容都是一致的,请使用“npm缓存验证”。国家预防机制错误!国家预防机制错误!如果您确定要删除整个缓存,请使用--force重新运行此命令。

所以:

npm cache clean --force

npm install

并得到了以下错误:

节点-前回转错误!堆栈TypeError:无法读取属性“版本”的null

因此,与gitHub一样,重构package-lock.json并再次删除包和缓存。

现在,尝试npm start使我走到了起点:

node_node/@type/jquery/index.d.ts(47,40):error 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:',‘预期。以此类推

package.json:

代码语言:javascript
复制
{
  "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文件时:

代码语言:javascript
复制
"@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是从哪里来的??

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-06-26 10:58:03

我在我的package.json中添加了下面的内容,修正了同样的错误

代码语言:javascript
复制
"devDependencies": {
...
"@types/jquery": "^2.0.42",
...
}

谢谢你的UPDATE2,所以我能找到这个@type/jquery吗?

票数 8
EN

Stack Overflow用户

发布于 2017-06-21 09:51:37

最后,我将打字本版本从2.2.0升级到2.3,从而使其工作起来。

那是一个巨大的标题。

我希望这能帮到别人。

票数 14
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44672035

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档