简体   繁体   English

在 Next.js 12 中使用 Bootstrap 和 SCSS

[英]Use Bootstrap in Next.js 12 with SCSS

After upgrading Next.js to version 12 Bootstrap with SCSS isn't working anymore.使用 SCSS 将 Next.js 升级到版本 12 Bootstrap 后不再工作。

I have a global.scss file which gets imported in the _app.js .我有一个global.scss文件,它被导入到_app.js In this file I import Bootstrap and Bootstrap Icons.在这个文件中,我导入了 Bootstrap 和 Bootstrap 图标。

@import '~bootstrap/scss/bootstrap.scss';
@import '~bootstrap-icons/font/bootstrap-icons.css';

It worked perfectly, but not after upgrading to Next.js 12. Now I get an import error and I don't know how to resolve it.它工作得很好,但在升级到 Next.js 12 之后就不行了。现在我收到一个导入错误,我不知道如何解决它。

./styles/global.scss:5:0
Module not found: Can't resolve '../node_modules/bootstrap/scss/forms/data:image/svg+xml,<svg xmlns='http:/www.w3.org/2000/svg' viewBox='0 0 16 16'><path fill='none' stroke=''

Import trace for requested module:
./styles/global.scss
./pages/_app.jsx

https://nextjs.org/docs/messages/module-not-found

This is a temporary workaround.这是一种临时解决方法。

$form-check-input-checked-bg-image: none;
$form-check-radio-checked-bg-image: none;
$form-check-input-indeterminate-bg-image: none;
$form-switch-bg-image: none;
$form-switch-focus-bg-image: none;
$form-switch-checked-bg-image: none;
$form-select-indicator: none;
$form-feedback-icon-valid: none;
$form-feedback-icon-invalid: none;
$navbar-light-toggler-icon-bg: none;
$navbar-dark-toggler-icon-bg: none;
$accordion-button-icon: none;
$accordion-button-active-icon: none;
$carousel-control-prev-icon-bg: none;
$carousel-control-next-icon-bg: none;
$btn-close-bg: none;

@import '~bootstrap/scss/bootstrap.scss';
@import '~bootstrap-icons/font/bootstrap-icons.css';

I just got this problem myself and using Cosmo workaround, but encountered a problem when using checkbox, the tick icon is missing.我自己刚刚遇到这个问题并使用 Cosmo 解决方法,但是在使用复选框时遇到了问题,缺少勾号图标。 to fix this, you can copy the image from bootstrap _variables.scss url("you copy this text") to a new file and save it as svg.要解决此问题,您可以将 bootstrap _variables.scss url("you copy this text") 中的图像复制到新文件并将其保存为 svg。

and change Cosmo workaround from none to this new svg path.并将 Cosmo 解决方法从无更改为这个新的 svg 路径。

_variables.scss _variables.scss

$form-check-input-checked-bg-image:       url("copy this text here") !default;

new_svg.svg new_svg.svg

paste the text here and save

global.scss global.scss

$form-check-input-checked-bg-image: url("path/to/new/new_svg.svg");

note: you might need to use '../../../' to your path, because it look for the file from bootstrap node_modules folder注意:您可能需要在路径中使用“../../../”,因为它会从 bootstrap node_modules 文件夹中查找文件

errror file @import "forms" enter code here @import "navbar" enter code here @import "accordion" enter code here @import "close" enter code here @import "carousel" enter code here @import "forms";错误文件 @import "forms" enter code here @import "navbar" enter code here @import "accordion" enter code here @import "close" enter code here @import "carousel" enter code here @import "forms"; enter image description here在此处输入图片说明

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM