SPA .netCore Angular 5:未捕获的参考错误:jQuery未定义

时间:2019-01-08 10:37:22

标签: javascript jquery angular asp.net-core webpack

我已将Angular应用程序从4更新到5.2。 Package.json:

{
  "name": "OneSOE",
  "private": true,
  "version": "0.0.0",
  "scripts": {
    "test": "karma start ClientApp/test/karma.conf.js"
  },
  "dependencies": {
    "@angular-redux/form": "^6.7.0",
    "@angular-redux/router": "^6.4.1",
    "@angular-redux/store": "^6.6.0",
    "@angular/animations": "^5.2.11",
    "@angular/common": "^5.2.11",
    "@angular/compiler": "^5.2.11",
    "@angular/compiler-cli": "^5.2.11",
    "@angular/core": "^5.2.11",
    "@angular/forms": "^5.2.11",
    "@angular/http": "^5.2.11",
    "@angular/platform-browser": "^5.2.11",
    "@angular/platform-browser-dynamic": "^5.2.11",
    "@angular/platform-server": "^5.2.11",
    "@angular/router": "^5.2.11",
    "@ng-select/ng-select": "0.25.0",
    "@ngtools/webpack": "^1.10.2",
    "@swimlane/ngx-datatable": "^11.3.2",
    "@types/chai": "4.0.1",
    "@types/file-saver": "0.0.1",
    "@types/jasmine": "2.5.53",
    "@types/node": "7.0.18",
    "@types/ramda": "0.25.8",
    "@types/webpack-env": "1.13.0",
    "alasql": "^0.4.11",
    "angular2-multiselect-dropdown": "^2.10.2",
    "angular2-router-loader": "0.3.5",
    "angular2-template-loader": "0.6.2",
    "aspnet-prerendering": "^3.0.1",
    "aspnet-webpack": "^2.0.3",
    "awesome-typescript-loader": "3.2.3",
    "bootstrap": "3.3.7",
    "chai": "4.0.2",
    "core-js": "^2.4.0",
    "css": "^2.2.4",
    "css-loader": "0.28.4",
    "es6-shim": "0.35.3",
    "event-source-polyfill": "0.0.9",
    "expose-loader": "0.7.3",
    "extract-text-webpack-plugin": "2.1.2",
    "file-loader": "^0.11.2",
    "file-saver": "^1.3.8",
    "flux-standard-action": "^1.2.0",
    "font-awesome": "^4.7.0",
    "isomorphic-fetch": "2.2.1",
    "jquery": "3.2.1",
    "ng-trim-value-accessor": "^2.0.4",
    "ngx-bootstrap": "^1.6.6",
    "ngx-cookie-service": "^1.0.10",
    "powerbi-client": "^2.6.6",
    "preboot": "4.5.2",
    "ramda": "^0.23.0",
    "raw-loader": "0.5.1",
    "redux": "^3.7.0",
    "redux-devtools-extension": "2.13.2",
    "redux-logger": "^3.0.1",
    "redux-observable": "^0.16.0",
    "reflect-metadata": "0.1.10",
    "rxjs": "^5.5.12",
    "style-loader": "0.18.2",
    "to-string-loader": "1.1.5",
    "ts-node": "^7.0.0",
    "ts-xlsx": "0.0.11",
    "typescript": "^2.5.1",
    "url-loader": "^1.1.2",
    "webpack": "^3.0.0",
    "webpack-hot-middleware": "2.18.2",
    "webpack-merge": "4.1.0",
    "zone.js": "0.8.12"
  },
  "devDependencies": {
    "html-loader": "^0.4.5",
    "jasmine-core": "^2.99.1",
    "json-loader": "0.5.4",
    "webpack-cli": "^3.1.0"
  }
}

我没有更改webpack.config.js中的任何内容。 但是我在运行应用程序时在过渡js中遇到错误: enter image description here

错误: enter image description here

  

我尝试将jquery引用添加到webpack文件中,但是没有运气

。但是更新之前不需要参考,因此我认为这不是解决方案。

1 个答案:

答案 0 :(得分:0)

使用npm安装JQuery:

npm install jquery --save

然后将其添加到angular-cli.json中的脚本中

"scripts": [ "../node_modules/jquery/dist/jquery.min.js" ]