【问题标题】:import bootstrap in angular 6 angular.json Error: ENOENT: no such file or directory在 Angular 6 angular.json 中导入引导程序错误:ENOENT:没有这样的文件或目录
【发布时间】:2018-10-21 04:15:40
【问题描述】:

在 Angular 6 中导入引导程序的正确方法是什么。在以前的版本中,我是这样做的并且它工作正常。

angular-cli.json(Angular 5)

"styles": [
    "styles.scss"
  ],
"scripts": [
    "../node_modules/jquery/dist/jquery.slim.min.js",
    "../node_modules/popper.js/dist/umd/popper.min.js",
    "../node_modules/bootstrap/dist/js/bootstrap.min.js"
  ],

angular.json(Angular 6)

"styles": [
          "src/styles.css"
        ],
"scripts": [
          "../node_modules/jquery/dist/jquery.slim.min.js",
          "../node_modules/popper.js/dist/umd/popper.min.js",
          "../node_modules/bootstrap/dist/js/bootstrap.min.js"
        ]

得到错误:

Error: ENOENT: no such file or directory, open '/Users/pacozevallos/myApp/node_modules/jquery/dist/jquery.slim.min.js'

【问题讨论】:

    标签: angular bootstrap-4


    【解决方案1】:

    我看到您的错误是显示缺少 jquery 文件。但是bootstrap 4不需要jquery。如果您使用的是命令 npm install --save @ng-bootstrap/ng-bootstrap 来自 angular-cli 我认为不需要 jquery 依赖项。 还需要在主模块和要实现引导样式的模块中添加 import 语句:

    import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
    

    不需要安装 jquery,可能会干扰 ng-bootstrap 代码。 也许您需要删除您可能安装的任何 jquery。

    【讨论】:

    • OP 说的是来自getbootstrap.combootstrap,而不是ng-bootstrap
    【解决方案2】:

    此配置应该可以工作,因为正如您在angular.json 文件中看到的那样,有用于导入文件的属性"root": "",,因此请按照以下代码进行操作

    "styles": [
       "src/styles.scss",
       "node_modules/bootstrap/dist/css/bootstrap.min.css"
    ],
    "scripts": [
       "node_modules/jquery/dist/jquery.slim.min.js",
       "node_modules/popper.js/dist/umd/popper.min.js",
       "node_modules/bootstrap/dist/js/bootstrap.min.js"
    ]
    

    【讨论】:

    • 这对我有用,我只是看到角度 6 的一些变化,感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 2017-10-07
    • 2019-02-23
    • 2016-11-03
    • 1970-01-01
    • 2019-03-09
    • 2017-12-28
    • 2022-01-16
    • 2021-03-30
    相关资源
    最近更新 更多