所以我不确定这是怎么回事,但当我在我的Angular 4项目中运行'npm install'时,它完全忽略了我在packages.json文件中指定的jQuery版本,并且它正在安装版本1.7.4。
我在package.json中指定了2.2.4 - 我正在运行bootstrap 3.3.7,并且任何比这更新的jQuery版本都会破坏bootstrap。
奇怪的是,当npm正在运行install时,我收到一条警告消息:npm WARN不推荐使用jQuery@1.7.4:这是不推荐使用的。请使用'jquery'(全小写)。但我不知道那是从哪里来的。我没有意识到任何地方都在指定jQuery 1.7.4。
有什么想法吗?
(编辑2017年8月10日:以下是我的package.json文件,请求。谢谢。)
{
"name": "smartadmin",
"version": "0.4.5",
"license": "WRAPBOOTSTRAP",
"angular-cli": {},
"scripts": {
"build:dev": "./node_modules/.bin/ng build",
"build:prod": "./node_modules/.bin/ng build --prod --aot=false",
"build:aot": "./node_modules/.bin/ng build --prod --aot",
"build:aot2": "node --max_old_space_size=4096 ./node_modules/.bin/ng build --prod --aot",
"build": "npm run build:dev",
"clean:dist": "npm run rimraf -- dist",
"clean:install": "npm set progress=false && npm install",
"clean:start": "npm start",
"clean": "npm cache clean && npm run rimraf -- node_modules doc coverage dist",
"e2e:live": "npm run e2e -- --elementExplorer",
"e2e": "npm run protractor",
"lint": "npm run tslint \"src/**/*.ts\"",
"postversion": "git push && git push --tags",
"prebuild:dev": "npm run clean:dist",
"prebuild:prod": "npm run clean:dist",
"preclean:install": "npm run clean",
"preclean:start": "npm run clean",
"preversion": "npm test",
"protractor": "protractor",
"rimraf": "rimraf",
"server:dev": "./node_modules/.bin/ng serve",
"server": "npm run server:dev",
"start": "npm run server:dev",
"test": "./node_modules/.bin/ng test",
"tslint": "tslint",
"typedoc": "typedoc",
"version": "npm run build",
"ng": "ng",
"pree2e": "webdriver-manager update --standalone false --gecko false"
},
"private": true,
"dependencies": {
"@angular-redux/store": "^6.3.0",
"@angular/animations": "^4.0.0",
"@angular/common": "^4.0.0",
"@angular/compiler": "^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/router": "^4.0.0",
"X-editable": "github:vitalets/x-editable",
"bootstrap": "^3.3.7",
"bootstrap-colorpicker": "^2.5.1",
"bootstrap-duallistbox": "^3.0.6",
"bootstrap-markdown": "^2.10.0",
"bootstrap-progressbar": "^0.9.0",
"bootstrap-slider": "^9.8.0",
"bootstrap-tagsinput": "^0.7.1",
"bootstrap-timepicker": "^0.5.2",
"chart.js": "^2.6.0",
"classlist.js": "^1.1.20150312",
"clockpicker": "^0.0.7",
"clone": "^2.1.1",
"core-js": "^2.4.1",
"debounce": "^1.0.2",
"dropzone": "^4.3.0",
"dygraphs": "^2.0.0",
"fuelux": "^3.16.0",
"he": "^1.1.1",
"highcharts": "^5.0.12",
"ion-rangeslider": "^2.1.7",
"jquery": "^2.2.4",
"jquery-color": "^1.0.0",
"jquery-jcrop": "^0.9.13",
"jquery-knob": "^1.2.11",
"jquery-ui-npm": "^1.12.0",
"jquery-validation": "^1.17.0",
"jquery.maskedinput": "^1.4.1",
"markdown": "^0.5.0",
"morris.js": "^0.5.0",
"ngx-bootstrap": "^2.0.0-beta.2",
"ngx-popover": "^0.0.16",
"nouislider": "^9.2.0",
"raphael": "^2.2.7",
"redux": "^3.6.0",
"rxjs": "^5.1.0",
"scriptjs": "^2.5.8",
"select2": "^4.0.3",
"smartadmin-plugins": "^1.0.20",
"summernote": "^0.8.3",
"to-markdown": "^3.0.4",
"ts-helpers": "^1.1.2",
"web-animations-js": "^2.2.5",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/cli": "^1.3.0",
"@angular/compiler-cli": "^4.0.0",
"@angular/language-service": "^4.0.0",
"@types/jasmine": "~2.5.53",
"@types/jquery": "2.0.45",
"@types/node": "~6.0.60",
"codelyzer": "~3.0.1",
"css-loader": "^0.28.3",
"exports-loader": "^0.6.4",
"expose-loader": "^0.7.3",
"file-loader": "^0.11.1",
"imports-loader": "^0.7.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-remap-istanbul": "^0.6.0",
"protractor": "~5.1.2",
"raw-loader": "^0.5.1",
"script-loader": "^0.7.0",
"style-loader": "^0.18.1",
"ts-node": "~3.0.4",
"tslint": "~5.3.2",
"typescript": "~2.3.3",
"url-loader": "^0.5.8"
},
"repository": {
"type": "git",
"url": "https://bitbucket.org/grigson/smartadmin-angular-2"
},
"bugs": {
"url": "https://bitbucket.org/grigson/smartadmin-angular-2/issues"
},
"engines": {
"node": ">= 4.2.1",
"npm": ">= 3"
}
}
更新(2017年8月14日)
我使用我在此处找到的说明完全删除了我的nodejs和npm安装:How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
以下是我使用的命令:
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp /opt/local/bin/node opt/local/include/node /opt/local/lib/node_modules
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
我还删除了一些其他'node'和'npm'文件夹和文件,我在浏览上面链接中提到的各个位置时找到了这些文件和文件(包括一个存在的/Users/[myusername]/.npm
文件夹... ...
然后我从nodejs.org下载了节点v6.11.2 .pkg文件,并进行了安装。它带有版本3.-npm,所以我将npm(npm install -g npm
)更新为版本5.3.0。
然后我安装了Angular / CLI 1.3.0(截至今天的最新版本)npm install -g @angular/cli@1.3.0
(我在上面更新了我的package.json以反映这个新版本的Angular,顺便说一下。)
然后我进入我的Angular项目文件夹并运行npm install
。
它安装了JQUERY 1.7.4再次!!!!! WTF?!!!!!!
我将我的package.json文件复制到一个空文件夹并运行npm install
并执行相同的操作 - jQuery 1.7.4。
阿勇!!! WTF正在这里?!!
如果有人有任何想法,我愿意接受任何建议。这很坚果!
答案 0 :(得分:3)
好的 - 我终于找到了为什么要这样做......
显然jQuery颜色选择器内置了一个jQuery 1.7.4依赖...
当我从package.json文件中删除"jquery-color": "^1.0.0",
时,它安装了jQuery 2.2.4而不是1.7.4 !!所以至少我想出了它从...获取jQuery 1.7.4的位置
我仍然不知道为什么这种依赖会迫使npm为整个项目安装错误版本的jQuery,尽管......这很奇怪......
答案 1 :(得分:1)
显然npm变为区分大小写或者什么东西当npm读取库jquery.color时它会加载旧的弃用的jQuery 1.7.4 ...我能够通过运行这个来使用jquery.color引用它/ p>
{{1}}
在安装了错误的jquery后,会强制安装正确版本的jquery
答案 2 :(得分:0)
尝试删除node_modules
文件夹并执行npm cache clean
。
再次运行npm install
如果您不小心用CDN行覆盖了jQuery版本,请检查index.html文件。