BrowserslistError: Unknown browser major

匿名 (未验证) 提交于 2019-12-03 02:06:01

问题:

I'm trying to use bootstrap 4 with my angular installation. i've run npm install --save bootstrap@next but i have a break at runtime :

./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

Can someone help please?

回答1:

The issue could be that you got the latest build with some bug. I noticed that bootstrap@4.0.0-beta.3 is causing this issue, but not bootstrap@4.0.0-beta.2. Check if yours is the same. Try uninstalling that and run something with a specific version.

npm install bootstrap@4.0.0-alpha.6

This resolved my problem.



回答2:

Bootstrap new version come which is v4.0.0-beta.2 and your package.json has ^bootstrap4.0.0-alpha.6 so new bootstrap version wants browsers list dependency.

To run your app remove lastest version tag (^) & run npm install command



回答3:

For Bootstrap 4.0.0 (release) I have to upgrade the CLI to 1.6.5 ― and it works!

  "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"   }


回答4:

I've upgraded to Angular CLI 1.7.x and it started working fine. I recommend this solution. I mean upgrading the Angular CLI and it should work for you!

Another workaround is deleting the below lines from node_modules/bootstrap/package.json

"browserslist": [ "last 1 major version", = 1%", = 45", "Firefox >= 38", "Edge >= 12", "Explorer >= 10", "iOS >= 9", "Safari >= 9", "Android >= 4.4", "Opera >= 30" ],


回答5:

Was having same issue changed my dependency in package.json from this

"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 (changing "bootstrap": "4.0.0-beta.2" to a stable version)

"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"   },

then,run: npm install ng serve

problem solved.!!



回答6:

Bootstrap 4 doesn't use CSS anymore. In this version the SCSS is used. So instead of importing '~bootstrap/scss/bootstrap.css', you should import '~bootstrap/scss/bootstrap.scss'.



回答7:

It works now without workaround with Angular CLI: 1.6.5. Angular CLI has been depending on an incompatible version of autoprefixer (https://github.com/angular/angular-cli/issues/9020)

Verify version by typing ng --version. Do not foget to update your dev dependency in package.json:

"@angular/cli": "1.6.5",


回答8:

For those still having problems:

Manually remove the url to bootsrap CSS from angular-cli.json

  "styles":   [     **"../node_modules/bootstrap/dist/css/bootstrap.min.css",**     "../node_modules/font-awesome/css/font-awesome.min.css",         "styles.css"   ]


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!