提问者:小点点

无法用引导程序编译angular


我试图开始一个项目与Angular,但我不能进一步因为错误:

“在multi./src/styles.css./node_modules/bootstrap/dist/css/bootstrap.min.css模块中找不到错误:”

依赖关系如下:

"dependencies": {
    "@angular/animations": "^6.0.3",
    "@angular/common": "^6.0.3",
    "@angular/compiler": "^6.0.3",
    "@angular/core": "^6.0.3",
    "@angular/forms": "^6.0.3",
    "@angular/http": "^6.0.3",
    "@angular/platform-browser": "^6.0.3",
    "@angular/platform-browser-dynamic": "^6.0.3",
    "@angular/router": "^6.0.3",
    "core-js": "^2.5.4",
    "rxjs": "^6.0.0",
    "zone.js": "^0.8.26",
    "bootstrap":  "3.3.7"
}

json(相关部分):

    "styles": [
        "src/styles.css"
    ],
    "scripts": []
},

devDependencies:

"devDependencies": {
    "@angular/compiler-cli": "^6.0.3",
    "@angular-devkit/build-angular": "~0.6.8",
    "typescript": "~2.7.2",
    "@angular/cli": "~6.0.8",
    "@angular/language-service": "^6.0.3",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1"
}

我已经尝试了stackoverflow的所有解决方案,但都没有效果。我试过:

"styles": [
      "src/styles.css",
      "node_modules/bootstrap/dist/css/bootstrap.css"
    ],
    "scripts": ["../node_modules/jquery/dist/jquery.js",
      "node_modules/bootstrap/dist/js/bootstrap.bundle.js"
  ]`

我尝试过组合不同版本的应用程序(例如angular 6、bootstrap 4等)

我尝试从包中删除node_modules/bootstrap/dist/css/bootstrap.css,并将其导入styles.css中

什么都不起作用,现在我没有想法,面对绝望和失败已经在33页的书“Pro Angular”亚当弗里曼。也许这里的某个人经历过这个问题,并且有上面提到的其他可行的解决方案?


共2个答案

匿名用户

您可以尝试将其添加到index.html中。尝试在标记的底部添加以下内容:

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

如果这不起作用,请尝试重新启动npm startng serve。有时,当您修改Angular.json时,您必须这样做。

匿名用户

试试看

"styles": [
      "node_modules/bootstrap/dist/css/bootstrap.min.css",
      "src/styles.css"

我读到bootstrap应该是第一个,然后是styles.css。我还添加了“min.css”,但我现在不记得它是否应该包含它了