简体   繁体   English

无法将Bootstrap 4,jQuery和PopperJS库添加到.angular-cli.json

[英]Couldn't add Bootstrap 4, jQuery, and PopperJS libraries to .angular-cli.json

Currently i'm trying to implement Bootstrap 4 navbar element on my Angular 5 project, and it needs three JS libraries, Bootstrap 4, jQuery, and PopperJS. 目前,我正在尝试在Angular 5项目上实现Bootstrap 4 navbar元素,它需要三个JS库,即Bootstrap 4,jQuery和PopperJS。

It works flawlessly (ie NO ERROR occurred) when I add following to src/index.html 当我在src/index.html添加以下内容时,它可以完美地工作(即没有错误发生)

<head>
...
...
...
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</head>

However, I wanted to do an experiment by adding those three JS libraries to the .angular-cli.json (instead of using CDN on src/index.html ), so I did following: 但是,我想做一个实验,将这三个JS库添加到.angular-cli.json (而不是在src/index.html上使用CDN),所以我做了以下工作:

On .angular-cli.json , i add: .angular-cli.json ,我添加:

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

Note: before adding those three scripts to .angular-cli.json I already installed Bootstrap 4, jQuery and PopperJS packages using npm . 注意:在将这三个脚本添加到.angular-cli.json我已经使用npm安装了Bootstrap 4,jQuery和PopperJS软件包。

When running it, there is an Error on console (Chrome Dev Tool) 运行它时,控制台上出现错误(Chrome开发工具)

Uncaught SyntaxError: Unexpected token export         scripts.bundle.js:2302

When clicking on the error message it brought to this line 当单击错误消息时,它显示到此行

export default Popper;

I'm kinda confused on what's happening and what's the real cause of the problem? 我对正在发生的事情以及问题的真正原因是什么感到困惑? How to fix this error? 如何解决这个错误?

  1. npm install --save bootstrap jquery popper.js
  2. angular-cli.json: angular-cli.json:

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

Now u can launch your app 现在您可以启动您的应用了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 脚本不从.angular-cli.json加载 - Scripts don't load from .angular-cli.json 弹出项目后的Angular-cli.json - Angular-cli.json after ejecting the project 在哪里将angular-cli.json内容放在Ionic 3应用程序上 - Where to put angular-cli.json content on Ionic 3 app Angular 2应用程序的初始加载速度较慢,原因是在angular-cli.json中添加了外部第三方js库 - Angular 2 app slow initial load because of added external third party js libs to angular-cli.json 如何在angular-cli.json样式部分中包含所有.less文件? - How to include all .less files in angular-cli.json styles section? angular-cli.json在添加style.css时创建错误 - angular-cli.json create error while adding style.css 使用angular-cli.json将文件从node_modules移动到资产 - Move a file from node_modules to assets using angular-cli.json 如何使用 jQuery slim 和新的@popperjs 与 Laravel-mix 构建 Bootstrap 4? - How to build Bootstrap 4 with jQuery slim and new @popperjs with Laravel-mix? 当与bootstrap4一起使用时,jquery未定义popperjs第2325行 - jquery is not defined popperjs line 2325 when used with bootstrap4 无法在 Angular 6 中添加 Bootstrap 4 - Can´t add Bootstrap 4 in Angular 6
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM