首页 文章

angular2-cli给出了@multi样式错误

提问于
浏览
4

我最近开始使用angular2-cli并创建了一个新项目 . 我想在我的项目中使用bootstrap,因此我安装了bootstrap然后想要导入bootstrap css文件,就像它在angular2-cli指南中所示 . https://github.com/angular/angular-cli#global-library-installation运行ng服务后,我收到以下错误 .

多样式中的错误找不到模块:错误:无法解析'/ home / krishna / angular2_migrate / webui /中的'/home/krishna/angular2_migrate/webui/node_modules/bootstrap/dist/css/bootstrap.min.css' node_modules / angular-cli / models'@多样式

我究竟做错了什么 ?

有关angular2-cli版本的信息

krishna@Krishna:~/angular2_migrate/webui$ ng version
Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://ember-cli.com/user-guide/#watchman for more info.
angular-cli: 1.0.0-beta.17
node: 4.4.3
os: linux x64

6 回答

  • 0

    在路径前添加../

    在angular-cli.json中,

    "styles": [
      "../node_modules/bootstrap/dist/css/bootstrap.min.css",
      "styles.scss"
    ]
    
  • 1

    我使用角度6所以我的文件名是angular.json,但我能够通过删除它要求的“../”路径来解决类似的问题 . 下面是我为我的角度应用程序添加bootstrap和jquery的设置 .

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

    请注意,对于jquery,我需要“../”而bootstap不需要它 .

    此外,本文还包含多个备用选项 .

    https://medium.com/@rogercodes1/intro-to-angular-and-how-to-setup-your-first-angular-app-b36c9c3ab6ca

  • 7

    在我的情况下,错误是因为我有

    "styles":[
          "styles.css"
        ]
    

    在我的.angular-cli.json中

    我通过手动输入我的所有SCRIPTS和CSS的路径来解决它 . 例如

    "styles":[
          "styles/bootstrap.scss",
          "styles/app.scss",
         ]
    

    angular-cli.json中的路径是相对于项目根目录(src /通常) . 例如,你有src / styles.css文件,但在angular-cli.json中它只列为styles.css .

  • 3

    这是我的修复 . 在你当前的目录中,你有一个名为.angular-cli.json的隐藏文件打开并将“style.sass”更改为“style.css:run ng build,你就完成了 .

    之前:
    enter image description here
    之后:
    enter image description here

  • 0

    我有同样的问题,但我通过提供文件的完整路径解决了这个问题,如下所示 "styles": [ "F:/Angular2Projects/Angular/myapp/node_modules/bootstrap/dist/css/bootstrap.min.css", "F:/Angular2Projects/Angular/my-app/src/styles.css" ],

  • 0

    下面的解决方案对我有用,因为似乎bootstrap 4.0中存在一个错误:

    npm uninstall bootstrap --save
    

    然后安装

    npm install bootstrap@3.3.7 --save
    

相关问题