BrowserslistError:未知的浏览器专业版

时间:2017-12-29 02:24:55

标签: javascript angular bootstrap-4

我尝试在角度安装时使用bootstrap 4。我跑了 npm install --save bootstrap @ next但我在运行时休息一下:

./node_modules/css-loader?{"sourceMap":false,"importLoaders":1}!./node_modules/postcss-loader/lib?{"ident":"postcss","plugins":[null,null,null],"sourceMap":false}!./node_modules/bootstrap/dist/css/bootstrap.min.css
Module build failed: BrowserslistError: Unknown browser major
    at error (C:\xampp\htdocs\tick_master_angular\web\node_modules\browserslist\index.js:37:11)
    at Function.browserslist.checkName (C:\xampp\htdocs\tick_master_angular\web\node_modules\browserslist\index.js:320:18)
    at Function.select (C:\xampp\htdocs\tick_master_angular\web\node_modules\browserslist\index.js:438:37)
    at C:\xampp\htdocs\tick_master_angular\web\node_modules\browserslist\index.js:207:41
    at Array.forEach (native)
    at browserslist (C:\xampp\htdocs\tick_master_angular\web\node_modules\browserslist\index.js:196:13)
    at Browsers.parse (C:\xampp\htdocs\tick_master_angular\web\node_modules\autoprefixer\lib\browsers.js:44:14)
    at new Browsers (C:\xampp\htdocs\tick_master_angular\web\node_modules\autoprefixer\lib\browsers.js:39:28)
    at loadPrefixes (C:\xampp\htdocs\tick_master_angular\web\node_modules\autoprefixer\lib\autoprefixer.js:56:18)
    at plugin (C:\xampp\htdocs\tick_master_angular\web\node_modules\autoprefixer\lib\autoprefixer.js:62:18)
    at LazyResult.run (C:\xampp\htdocs\tick_master_angular\web\node_modules\postcss-loader\node_modules\postcss\lib\lazy-result.js:270:20)
    at LazyResult.asyncTick (C:\xampp\htdocs\tick_master_angular\web\node_modules\postcss-loader\node_modules\postcss\lib\lazy-result.js:185:32)
    at LazyResult.asyncTick (C:\xampp\htdocs\tick_master_angular\web\node_modules\postcss-loader\node_modules\postcss\lib\lazy-result.js:197:22)
    at processing.Promise.then._this2.processed (C:\xampp\htdocs\tick_master_angular\web\node_modules\postcss-loader\node_modules\postcss\lib\lazy-result.js:224:20)
    at LazyResult.async (C:\xampp\htdocs\tick_master_angular\web\node_modules\postcss-loader\node_modules\postcss\lib\lazy-result.js:221:27)
    at LazyResult.then (C:\xampp\htdocs\tick_master_angular\web\node_modules\postcss-loader\node_modules\postcss\lib\lazy-result.js:127:21)
 @ ./node_modules/css-loader?{"sourceMap":false,"importLoaders":1}!./node_modules/postcss-loader/lib?{"ident":"postcss","sourceMap":false}!./src/styles.css 3:10-190
 @ ./src/styles.css
 @ multi ./src/styles.css

有人可以帮忙吗?

9 个答案:

答案 0 :(得分:14)

问题可能是你得到了一些有bug的最新版本。我注意到bootstrap@4.0.0-beta.3导致了这个问题,但不是bootstrap@4.0.0-beta.2。检查你的是否相同。尝试卸载并运行具有特定版本的内容。

npm install bootstrap@4.0.0-alpha.6

这解决了我的问题。

答案 1 :(得分:12)

Bootstrap新版本是v4.0.0-beta.2,你的package.json有^ bootstrap4.0.0-alpha.6所以新的bootstrap版本需要浏览器列表依赖。

要运行您的应用删除最新版本标记(^)&运行npm install命令

答案 2 :(得分:7)

对于Bootstrap 4.0.0(发布)我必须将CLI升级到1.6.5 - 它可以工作!

  "dependencies": {
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "@ng-bootstrap/ng-bootstrap": "1.0.0-beta.9",
    "bootstrap": "4.0.0",
    "core-js": "^2.4.1",
    "font-awesome": "^4.7.0",
    "jquery": "^3.2.1",
    "popper.js": "^1.12.9",
    "rxjs": "^5.5.2",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "^1.6.5",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.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",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.4.2"
  }

答案 3 :(得分:5)

我已升级到Angular CLI 1.7.x,它开始正常运行。我推荐这个解决方案。我的意思是升级Angular CLI,它应该适合你!

另一种解决方法是从 node_modules / bootstrap / package.json

中删除以下行
"browserslist": [
"last 1 major version", <----- delete this line
">= 1%", <----- delete this line
"Chrome >= 45",
"Firefox >= 38",
"Edge >= 12",
"Explorer >= 10",
"iOS >= 9",
"Safari >= 9",
"Android >= 4.4",
"Opera >= 30"
],

答案 4 :(得分:2)

有同样的问题从这个

改变了我对package.json的依赖性
"dependencies": {
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.9",
    "bootstrap": "^4.0.0-beta.3",
    "core-js": "^2.4.1",
    "font-awesome": "^4.7.0",
    "zone.js": "^0.8.14"
  }

to(将“bootstrap”:“4.0.0-beta.2”更改为稳定版本)

"dependencies": {
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.9",
    "bootstrap": "4.0.0-beta.2",
    "core-js": "^2.4.1",
    "font-awesome": "^4.7.0",
    "zone.js": "^0.8.14"
  },

然后,运行: npm安装 服务

问题解决了。!!

答案 5 :(得分:0)

Bootstrap 4不再使用CSS了。在此版本中使用SCSS。所以不是导入'~bootstrap/scss/bootstrap.css', 你应该导入'~bootstrap/scss/bootstrap.scss'

答案 6 :(得分:0)

我在Bootstrap 4.1.1中遇到了同样的问题。解决方案是在package.json中将Boostrap版本更改为4.0.0-beta.2(无尖号),然后运行

npm install 
ng serve

还要在您的import "~bootstrap/dist/css.bootstrap.css"文件中添加style.css

答案 7 :(得分:-1)

现在可以使用 Angular CLI解决方法:1.6.5 。 Angular CLI一直依赖于不兼容的autoprefixer版本(https://github.com/angular/angular-cli/issues/9020

输入 ng --version 验证版本。不要忘记在package.json中更新你的dev依赖:

"@angular/cli": "1.6.5",

答案 8 :(得分:-1)

对于仍有问题的人:

从angular-cli.json

手动删除bootrap CSS的url
  "styles":
  [
    **"../node_modules/bootstrap/dist/css/bootstrap.min.css",**
    "../node_modules/font-awesome/css/font-awesome.min.css",    
    "styles.css"
  ]