如何修复此错误:"找不到模块:无法解析 popper.js " [英] How to fix this error : " Module not found :can't resolve popper.js "

查看:35
本文介绍了如何修复此错误:"找不到模块:无法解析 popper.js "的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

导入 Bootstrap 和 Jquery 后,编译时出现此错误.

After import the Bootstrap and Jquery this error is showning when compiling.

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import 'bootstrap/dist/css/bootstrap.css';
import './index.css';

global.jQuery = require('jquery');
require('bootstrap');

推荐答案

Popper.js 是 Bootstrap 4 的一个依赖项,用于显示弹出窗口.它是引导程序的对等依赖项,这意味着它是引导程序需要但在安装时不包含在自身中的东西.所以要安装 popper.js 运行

Popper.js is a dependency of Bootstrap 4 which is used for showing popups. It is a peer dependency of bootstrap meaning it is something that bootstrap requires but doesn't include with itself when installed. So to install popper.js run

npm install popper.js --save

它被设置为对等依赖,因为有些人只使用 Bootstrap 的 css 而没有 javascript.jQuery 和 popper.js 是对等依赖,需要单独安装.如果你需要 Bootstrap 的 javascript,你需要在 Bootstrap 4 旁边安装 jQuery 和 popper.js.

It is setup as a peer dependency because some people just use the css of Bootstrap without the javascript. jQuery and popper.js are the peer dependencies which needs to be installed separately. If you require the javascript of Bootstrap you need to install jQuery and popper.js alongside Bootstrap 4.

Bootstrap 5 需要Popper.js 核心",而不是 Popper.js.你应该运行这个:

Bootstrap 5 requires "Popper.js Core", not Popper.js. You should run this instead:

npm install @popperjs/core --save

(感谢@Kyouma 在评论中添加此内容)

(thanks @Kyouma for adding this in the comments)

这篇关于如何修复此错误:"找不到模块:无法解析 popper.js "的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆