React-bootstrap 抛出错误“您可能需要适当的加载器来处理此文件类型”

STE*_*gns 6 reactjs twitter-bootstrap-3 react-bootstrap

我正在尝试使用https://react-bootstrap.github.io/上的包

它只是说你必须 npm 安装该软件包,然后对浏览器全局变量有一些非常模糊的说明:

We provide react-bootstrap.js and react-bootstrap.min.js bundles with all components exported on the window.ReactBootstrap object. These bundles are available on unpkg, as well as in the npm package.

<script src="https://unpkg.com/react/umd/react.production.min.js" crossorigin></script>

<script
  src="https://unpkg.com/react-dom/umd/react-dom.production.min.js"
  crossorigin></script>

<script
  src="https://unpkg.com/react-bootstrap@next/dist/react-bootstrap.min.js"
  crossorigin></script>

<script>var Alert = ReactBootstrap.Alert;</script>
Run Code Online (Sandbox Code Playgroud)

以及他们提供的 CDN。

How and which Bootstrap styles you include is up to you, but the simplest way is to include the latest styles from the CDN. A little more information about the benefits of using a CDN can be found here.
<link
  rel="stylesheet"
  href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
  integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
  crossorigin="anonymous"
/>
Run Code Online (Sandbox Code Playgroud)

我将包下载到本地react目录中,其中有我的public、src、package.json等。一旦我尝试使用包装中的组件,就会出现以下错误:

Failed to compile.

Error in ./~/react-bootstrap/cjs/Container.js
Module parse failed: C:\Users\joemo\Documents\Active\JoeOMGWorks\joeomgworks\node_modules\react-bootstrap\cjs\Container.js Unexpected token (29:2)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (29:2)
 @ ./src/Components/GlobalHeader.js 17:17-53
You may need an appropriate loader to handle this file type.
Run Code Online (Sandbox Code Playgroud)

该消息超出了我的知识范围。关于它是否是我必须做的 webpack 配置,或者我是否必须下载额外的东西,没有明确的答案。查看 Container.js (29:2) 如下:

23 const Container = /*#__PURE__*/React.forwardRef(({
24  bsPrefix,
25  fluid,
26  // Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
27 as: Component = 'div',
28  className,
**29  ...props**
30}, ref) => {
31  const prefix = (0, _ThemeProvider.useBootstrapPrefix)(bsPrefix, 'container');
32  const suffix = typeof fluid === 'string' ? `-${fluid}` : '-fluid';
33  return /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
34    ref: ref,
35    ...props,
36    className: (0, _classnames.default)(className, fluid ? `${prefix}${suffix}` : prefix)
37  });
38});
Run Code Online (Sandbox Code Playgroud)

合适的加载器到底是什么?为什么它没有包含在 npm 下载中,或者为什么我需要这个 npm 包的加载器?不幸的是,这是使用这个包的第一步。这不是一个好的开始。