简体   繁体   English

Fullcalendar 错误:请在尝试导入插件之前导入顶级 fullcalendar 库(Create-React-App & Craco.config.js)

[英]Fullcalendar Error: Please import the top-level fullcalendar lib before attempting to import a plugin (Create-React-App & Craco.config.js)

Below code works fine if the lines are commented out but if I uncomment the lines below in the code I am getting the error shown below in the image.如果注释掉这些行,下面的代码可以正常工作,但是如果我在代码中取消注释下面的行,我会收到图像中显示的错误。 I couldn't find any similar examples online related the issue.我在网上找不到与该问题相关的任何类似示例。

import React from "react";
import FullCalendar from "@fullcalendar/react";
import dayGridPlugin from "@fullcalendar/daygrid";
import timeGridPlugin from "@fullcalendar/timegrid";
// import listGridPlugin from "@fullcalendar/list"; // Throwing an error if this line is uncommented 
// import interactionPlugin from "@fullcalendar/interacti1on"; // Throwing an error if this line is uncommented 

const DemoApp = () => {
  return (
    <div>
      <div className="calendar">
        <FullCalendar
          plugins={[
            dayGridPlugin,
            timeGridPlugin,
            // interactionPlugin, // Throwing an error if this line is uncommented 
            // listGridPlugin, // Throwing an error if this line is uncommented 
          ]}
          headerToolbar={{
            left: "today prev,next prevYear,nextYear",
            center: "title",
            right: "dayGridMonth,timeGridWeek,timeGridDay,listMonth",
          }}
          initialView="dayGridMonth"
          events={[
            { title: "event 1", date: "2020-06-01" },
            { title: "event 2", date: "2020-06-04" },
            { title: "event 2", date: "2020-06-10" },
            { title: "event 2", date: "2020-06-17" },
          ]}
        />
      </div>
    </div>
  );
};

export default DemoApp;

I have created my app using create-react-app template and I am using craco.config.js (used this for the purposes of Ant design ) shown below.我已经使用 create-react-app 模板创建了我的应用程序,并且我正在使用 craco.config.js(用于 Ant 设计的目的),如下所示。 I am struggling to override the webpack settings as suggested the fullcalendar documentation.我正在努力按照 fullcalendar 文档的建议覆盖 webpack 设置。 When I downloaded the fullcalendar examples for react it works perfectly fine with webpack-config.js file.当我下载 fullcalendar 示例进行反应时,它与 webpack-config.js 文件完美配合。 As I am using create-react-app template with craco.config.js I am not sure how to load css-loader settings in craco.config.js file.当我使用带有 craco.config.js 的 create-react-app 模板时,我不确定如何在 craco.config.js 文件中加载 css-loader 设置。

Any suggestions or advice would be of great help.任何建议或意见都会有很大帮助。

Thank you very much for your time in advance.非常感谢您提前抽出宝贵时间。

package.json file package.json文件

  "scripts": {
    "start": "craco start",
    "build": "craco build",
    "test": "craco test"
  },

craco.config.js file craco.config.js 文件

const CracoLessPlugin = require('craco-less');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const packageMeta = require('./package.json');

module.exports = {
  // webpack: {
  //   module: {
  //     rules: [
  //       {
  //         test: /\.(js|jsx)$/,
  //         exclude: /node_modules/,
  //         use: 'babel-loader', // will use .babelrc
  //       },
  //       {
  //         test: /\.css$/,
  //         use: ['style-loader', 'css-loader'],
  //       },
  //     ],
  //   },
  //   plugins: [
  //     { plugin: HtmlWebpackPlugin, options: { title: packageMeta.title } },
  //   ],
  // },
  module: {
    rules: [
      {
        test: /\.css$/i,
        use: ['style-loader', 'css-loader'],
      },
    ],
  },
  plugins: [
    {
      plugin: CracoLessPlugin,
      options: {
        lessLoaderOptions: {
          lessOptions: {
            // modifyVars: { '@primary-color': '#0092ff' },
            modifyVars: { '@primary-color': '#3476cc' },
            javascriptEnabled: true,
          },
        },
      },
    },
  ],
};

错误

Found the answer.找到了答案。 FullCalendar works absolutely fine with create-react-app template with craco.config.js and there is no need to override any webpack settings in the craco.config.js file. FullCalendar 与带有 craco.config.js 的 create-react-app 模板完美配合,无需覆盖 craco.config.js 文件中的任何 webpack 设置。

Steps followed to resolve the issue.为解决问题而采取的步骤。 Created a new project with create-react-app template and installed fullcalendar packages and it worked fine.使用 create-react-app 模板创建了一个新项目并安装了 fullcalendar 包,它运行良好。 So, I deleted all fullcalendar npm packages in the project and started from scratch again, when I re-installed all packages everything working aboslutely fine.因此,我删除了项目中的所有 fullcalendar npm 包,然后重新从头开始,当我重新安装所有包时,一切正常。 Something might have got corrupted previously but is working now.有些东西以前可能已经损坏,但现在正在工作。

Thank you everyone if you have looked into it.如果您调查过,谢谢大家。

暂无
暂无

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

相关问题 fullcalendar - “请在尝试导入插件之前导入顶级 fullcalendar 库” - fullcalendar - “Please import the top-level fullcalendar lib before attempting to import a plugin” 在尝试导入插件 angular 之前出错 fullcalendar lib - Error fullcalendar lib before attempting to import a plugin angular 在 React 中使用 fullcalendar v4 导入 rrule 插件 - import rrule plugin with fullcalendar v4 in React 尝试在 create-react-app 中导入 npm 时出错 - Error while trying to import npm got in create-react-app 使用 babel-plugin-import 导入根目录不适用于 Create-React-App - Import root directory using babel-plugin-import is not working with Create-React-App 在 create-react-app 中有条件地导入资产 - Conditionally import assets in create-react-app 将 bootstrap 5 组件导入 create-react-app - Import bootstrap 5 component into create-react-app Google Apps 脚本 + React Web 应用程序错误按钮提交“不安全 Javascript 尝试...框架正在尝试导航顶级窗口” - Google Apps Script + React Web app error on button submit “Unsafe Javascript attempt…The Frame is attempting navigation of the top-level window” 如何在 craco 中使用 create-react-app 目录之外的 js 文件? - How to use a js file from outside of create-react-app directory, with craco? 在 (`create-react-app`) React.js 应用程序中,在哪里为组件导入样式表? - Where to import stylesheets for components in (`create-react-app`) React.js app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM