简体   繁体   English

Angular + bootstrap throws error 拒绝加载图像,因为它违反了以下内容安全策略指令:“default-src 'none'”

[英]Angular + bootstrap throws error Refused to load the image because it violates the following Content Security Policy directive: “default-src 'none'”

I am new to development with Angular, but not new to NPM and Bootstrap.我是使用 Angular 开发的新手,但对 NPM 和 Bootstrap 并不陌生。 I was doing a tutorial where I copy and pasted text off of the bootstrap website, installed ng-bootstrap and bootstrap-scss via npm, clicked refresh on the browser and it returns the above error.我正在做一个教程,我从引导网站复制和粘贴文本,通过 npm 安装 ng-bootstrap 和 bootstrap-scss,单击浏览器上的刷新并返回上述错误。 After running ng-serve, the terminal also says it cannot find the bootstrap import, which is weird given my file structure is the same as bootstrap website and everything about my app is copy pasted straight from docs.运行 ng-serve 后,终端还说找不到引导程序导入,这很奇怪,因为我的文件结构与引导程序网站相同,而且我的应用程序的所有内容都是直接从文档中复制粘贴的。 ng-serve worked to display text alone, but started throwing an error when I added the bootstrap link. ng-serve 可以单独显示文本,但是当我添加引导链接时开始抛出错误。

I found this same issue listed under Angular support on github, and the official angular support commented that the issue was nonexistent.我在 github 的 Angular 支持下发现了同样的问题,官方 angular 支持评论说该问题不存在。 After that, there were 30 comments from different people who have this issue.之后,有 30 条来自有此问题的不同人的评论。 I have tried running rebuild node-sass, deleting and reinstalling node_modules, and changing package.json, all to no avail.我尝试运行重建 node-sass,删除并重新安装 node_modules,并更改 package.json,但均无济于事。

Here is my app.module.ts:这是我的 app.module.ts:

import { NgModule } from '@angular/core';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap'
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule, NgbModule,
    AppRoutingModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }




The HTML code was copied from https://ng-bootstrap.github.io/#/components/accordion/examples HTML 代码是从https://ng-bootstrap.github.io/#/components/accordion/examples复制而来的

And the only thing in my scss file is我的 scss 文件中唯一的东西是

@import "../node_modules/bootstrap/scss/bootstrap"; @import "../node_modules/bootstrap/scss/bootstrap";

No other files within the project have been changed.项目中没有其他文件被更改。

Expected: the page will load styled text and widgets.预期:页面将加载样式化的文本和小部件。

Output in browser: 'Cannot get /' And in browser console: Refused to load the image ' http://localhost:4200/favicon.ico ' because it violates the following Content Security Policy directive: "default-src 'none'". Output 在浏览器中:'无法获取/'并且在浏览器控制台中:拒绝加载图像' http://localhost:4200/favicon.ico ',因为它违反了以下内容安全策略指令:“default-src 'none'” . Note that 'img-src' was not explicitly set, so 'default-src' is used as a fallback.请注意,'img-src' 没有显式设置,因此 'default-src' 用作后备。

I fixed it.我修好了它。 If you want to use scss for your project, copying the default node_modules path from bootstrap does not work.如果你想为你的项目使用 scss,从 bootstrap 复制默认的 node_modules 路径是行不通的。 I made my bootstrap styling show up by changing my file path within styles.scss to @import "../node_modules/bootstrap-scss/bootstrap";我通过将 styles.scss 中的文件路径更改为 @import "../node_modules/bootstrap-scss/bootstrap"; 来显示我的引导样式。

暂无
暂无

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

相关问题 拒绝加载图像,因为它违反了以下内容安全策略指令:“default-src 'none'”。 角度 8 - Refused to load the image because it violates the following Content Security Policy directive: "default-src 'none'". Angular 8 获取“违反以下内容安全策略指令:”default-src 'none'”。将 Angular 应用程序部署到 heroku 时出错 - Getting a "violates the following Content Security Policy directive: "default-src 'none'". error when deploying an angular app to heroku Angular 8 拒绝加载加载图像,因为它违反了以下内容安全策略指令 - Angular 8 refused to load load the image because it violates the following Content Security Policy directive 错误号 angular:“拒绝执行内联脚本,因为它违反了以下内容安全策略指令:“script-src 'self'” - Error no angular: "Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'" 拒绝加载图像,因为它违反了以下内容安全策略指令(图标) - Refused to load the image because it violates the following Content Security Policy directive (favicon) 无法在重新加载页面上获取 /login Angular 8 - 拒绝加载图像“/favicon.ico”,因为它违反了以下内容安全策略 - Cannot GET /login on reload pages Angular 8 - Refused to load the image '/favicon.ico' because it violates the following Content Security Policy 角路由“拒绝加载字体”,因为它违反了以下内容安全策略” - Angular routing 'Refused to load the font '…' because it violates the following Content Security Policy' AngularSplitModule CSP问题-由于违反CPS指令:“ default-src'self'”而拒绝加载图像 - AngularSplitModule CSP issue - refused to load image because violating CPS directive: “default-src 'self'” 无法在生产中加载图像,违反内容安全策略指令:“img-src 'self' data - Cannot load images on production, violates Content Security Policy directive: "img-src 'self' data 内容安全策略指令:拒绝加载字体 - Content Security Policy directive: Refused to load the font
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM