简体   繁体   English

"使用 swiperjs React 时出错 - `请求的模块 'react' 应该是 CommonJS 类型`"

[英]Error using swiperjs React - `The requested module 'react' is expected to be of type CommonJS`

I am building a React application.我正在构建一个 React 应用程序。 I am new to React and JS in general.一般来说,我是 React 和 JS 的新手。

I try importing the swiperjs<\/code> library into an existing React project:我尝试将swiperjs<\/code>库导入现有的 React 项目:

import React, { Component } from "react";
import { Swiper, SwiperSlide } from 'swiper/react';

function HomeBanner(props) {

    return (
        <div >
            <div>
                <img src="img/slider/home-3/home-banner/1.jpg" alt="" />
                <div className="">
                    <h5>Mega Sale Nov 2019</h5>
                    <h3>
                        Double Combo With <br />
                        The Body Shop
                    </h3>
                    <p>Sale up to <strong>50% Off </strong></p>
                    <a className="ps-btn" href="#">Shop Now</a>
                </div>
            </div>
            <div>
                <img src="img/slider/home-3/home-banner/2.jpg" alt="" />
                <div className="">
                    <h5>Mega Sale Nov 2017</h5>
                    <h3>
                        IKEA Minimalist <br />
                        Otoman
                    </h3>
                    <p>Discount <strong>50% Off </strong></p>
                    <a className="ps-btn" href="#">Shop Now</a>
                </div>
            </div>
        </div>
    )
}

Your development environment does not support ESM packages.您的开发环境不支持 ESM 包。 Check your version of Node by running node -v<\/code> .通过运行node -v<\/code>检查您的 Node 版本。 Node 14 and above supports ESM import. Node 14 及以上版本支持 ESM 导入。 Update the Node version or use Swiper 6.更新 Node 版本或使用 Swiper 6。

"

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

相关问题 SyntaxError:请求的模块“react-popper”应为 CommonJS 类型,不支持命名导出 - SyntaxError: The requested module 'react-popper' is expected to be of type CommonJS, which does not support named exports 请求的模块“graphql”应为 CommonJS 类型 - The requested module 'graphql' is expected to be of type CommonJS 在 TypeScript 中从 rrule 包导入 RRule。 获取 SyntaxError:请求的模块“rrule”应为 CommonJS 类型 - Importing RRule from rrule package in TypeScript. Getting SyntaxError: The requested module 'rrule' is expected to be of type CommonJS 使用CommonJS的反应路由器历史 - react-router history using CommonJS 错误:元素类型无效:预期为字符串React - Error: Element type is invalid: expected a string React React 和 Typescript,出现“预期类型”错误 - React and Typescript, getting "Type expected" error React.js-组件作为CommonJS模块-事件不起作用 - React.js - Component as CommonJS Module - Events not working 类型错误:react Js 中的预期参数 accessToken - Type error: expected parameter accessToken in react Js React SwiperJs 自动播放不会使刷卡器自动刷卡 - React SwiperJs autoplay not making the swiper to auto swipe React SwiperJS:水平嵌套 swiper 组件 - React SwiperJS: horizontally nesting swiper components
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM