Invalid plugin umi-plugin-react,[object Object], it must be string.

项目链接 提取码:1111
下面是启动时报错信息以及项目的相关配置文件,求解决,试了网上好多种方法都不行

umidev 启动报错

img

package.json文件

{
  "name": "ant-design-pro",
  "version": "2.1.0",
  "description": "An out-of-box UI solution for enterprise applications",
  "private": true,
  "scripts": {
    "presite": "node ./scripts/generateMock.js && cd functions && npm install",
    "start": "cross-env APP_TYPE=site umi dev",
    "start:no-mock": "cross-env MOCK=none umi dev",
    "build": "umi build",
    "site": "npm run presite && cross-env APP_TYPE=site npm run build && firebase deploy",
    "analyze": "cross-env ANALYZE=1 umi build",
    "lint:style": "stylelint \"src/**/*.less\" --syntax less",
    "lint": "eslint --ext .js src mock tests && npm run lint:style",
    "lint:fix": "eslint --fix --ext .js src mock tests && npm run lint:style",
    "lint-staged": "lint-staged",
    "lint-staged:js": "eslint --ext .js",
    "test": "umi test",
    "test:component": "umi test ./src/components",
    "test:all": "node ./tests/run-tests.js",
    "prettier": "prettier --write ./src/**/**/**/*",
    "docker:dev": "docker-compose -f ./docker/docker-compose.dev.yml up",
    "docker:build": "docker-compose -f ./docker/docker-compose.dev.yml build",
    "docker-prod:dev": "docker-compose -f ./docker/docker-compose.yml up",
    "docker-prod:build": "docker-compose -f ./docker/docker-compose.yml build"
  },
  "dependencies": {
    "@antv/data-set": "^0.9.6",
    "@babel/runtime": "^7.1.2",
    "antd": "^3.10.0",
    "bizcharts": "^3.2.2",
    "bizcharts-plugin-slider": "^2.0.3",
    "classnames": "^2.2.6",
    "dva": "^2.4.0",
    "dva-core": "1.1.0",
    "enquire-js": "^0.2.1",
    "hash.js": "^1.1.5",
    "lodash": "^4.17.10",
    "lodash-decorators": "^6.0.0",
    "memoize-one": "^4.0.0",
    "moment": "^2.22.2",
    "numeral": "^2.0.6",
    "nzh": "^1.0.3",
    "omit.js": "^1.0.0",
    "path-to-regexp": "^2.4.0",
    "prop-types": "^15.5.10",
    "qs": "^6.5.2",
    "rc-animate": "^2.4.4",
    "react": "^16.5.1",
    "react-container-query": "^0.11.0",
    "react-copy-to-clipboard": "^5.0.1",
    "react-document-title": "^2.0.3",
    "react-dom": "^16.5.1",
    "react-fittext": "^1.0.0",
    "react-router-dom": "^4.3.1"
  },
  "devDependencies": {
    "@types/react": "^16.4.16",
    "@types/react-dom": "^16.0.9",
    "antd-pro-merge-less": "^0.0.9",
    "antd-theme-webpack-plugin": "^1.1.8",
    "babel-eslint": "^10.0.1",
    "cross-env": "^5.1.1",
    "cross-port-killer": "^1.0.1",
    "enzyme": "^3.7.0",
    "eslint": "^5.4.0",
    "eslint-config-airbnb": "^17.0.0",
    "eslint-config-prettier": "^3.0.1",
    "eslint-plugin-babel": "^5.1.0",
    "eslint-plugin-compat": "^2.6.2",
    "eslint-plugin-import": "^2.8.0",
    "eslint-plugin-jsx-a11y": "^6.1.2",
    "eslint-plugin-markdown": "^1.0.0-beta.6",
    "eslint-plugin-react": "^7.11.1",
    "gh-pages": "^2.0.1",
    "husky": "^1.1.2",
    "lint-staged": "^7.2.0",
    "merge-umi-mock-data": "^0.0.3",
    "mockjs": "^1.0.1-beta3",
    "prettier": "1.14.3",
    "pro-download": "^1.0.1",
    "stylelint": "^9.4.0",
    "stylelint-config-prettier": "^4.0.0",
    "stylelint-config-standard": "^18.0.0",
    "umi": "^2.1.2",
    "umi-plugin-ga": "^1.1.3",
    "umi-plugin-react": "^1.1.1"
  },
  "optionalDependencies": {
    "puppeteer": "^1.9.0"
  },
  "lint-staged": {
    "**/*.{js,jsx,less}": [
      "prettier --write",
      "git add"
    ],
    "**/*.{js,jsx}": "npm run lint-staged:js",
    "**/*.less": "stylelint --syntax less"
  },
  "engines": {
    "node": ">=8.0.0"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 10"
  ],
  "husky": {
    "hooks": {
      "pre-commit": "npm run lint-staged"
    }
  }
}

config.js文件


// https://umijs.org/config/
import os from 'os';
import pageRoutes from './router.config';
import webpackPlugin from './plugin.config';
import defaultSettings from '../src/defaultSettings';

export default {
  // add for transfer to umi
  plugins: [
    [
      'umi-plugin-react',
      {
        antd: true,
        dva: {
          hmr: true,
        },
        targets: {
          ie: 11,
        },
        locale: {
          enable: true, // default false
          default: 'zh-CN', // default zh-CN
          baseNavigator: true, // default true, when it is true, will use `navigator.language` overwrite default
        },
        dynamicImport: {
          loadingComponent: './components/PageLoading/index',
        },
        ...(!process.env.TEST && os.platform() === 'darwin'
          ? {
              dll: {
                include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
                exclude: ['@babel/runtime'],
              },
              hardSource: true,
            }
          : {}),
      },
    ],
    [
      'umi-plugin-ga',
      {
        code: 'UA-72788897-6',
        judge: () => process.env.APP_TYPE === 'site',
      },
    ],
  ],
  targets: {
    ie: 11,
  },
  define: {
    APP_TYPE: process.env.APP_TYPE || '',
  },
  // 路由配置
  routes: pageRoutes,
  // Theme for antd
  // https://ant.design/docs/react/customize-theme-cn
  theme: {
    'primary-color': defaultSettings.primaryColor,
  },
  externals: {
    '@antv/data-set': 'DataSet',
  },
  // proxy: {
  //   '/server/api/': {
  //     target: 'https://preview.pro.ant.design/',
  //     changeOrigin: true,
  //     pathRewrite: { '^/server': '' },
  //   },
  // },
  ignoreMomentLocale: true,
  lessLoaderOptions: {
    javascriptEnabled: true,
  },
  disableRedirectHoist: true,
  cssLoaderOptions: {
    modules: true,
    getLocalIdent: (context, localIdentName, localName) => {
      if (
        context.resourcePath.includes('node_modules') ||
        context.resourcePath.includes('ant.design.pro.less') ||
        context.resourcePath.includes('global.less')
      ) {
        return localName;
      }
      const match = context.resourcePath.match(/src(.*)/);
      if (match && match[1]) {
        const antdProPath = match[1].replace('.less', '');
        const arr = antdProPath
          .split('/')
          .map(a => a.replace(/([A-Z])/g, '-$1'))
          .map(a => a.toLowerCase());
        return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
      }
      return localName;
    },
  },
  manifest: {
    name: 'ant-design-pro',
    background_color: '#FFF',
    description: 'An out-of-box UI solution for enterprise applications as a React boilerplate.',
    display: 'standalone',
    start_url: '/index.html',
    icons: [
      {
        src: '/favicon.png',
        sizes: '48x48',
        type: 'image/png',
      },
    ],
  },

  chainWebpack: webpackPlugin,
  cssnano: {
    mergeRules: false,
  },
};

有后端吗

能运行,没报错呀?
我的步骤:

# 1. 在项目文件夹(**/itcast-haoke-manage-web)中执行:
npm i

# 2. 启动项目:npm start 或者 npx umi dev
npm start

# 3. 成功启动

img

img

以下内容部分参考ChatGPT模型:


根据报错信息,是由于 umi-plugin-react 插件配置不正确导致的。请检查你的 .umirc.js 配置文件中的 plugins 部分,确保 umi-plugin-react 配置为字符串形式,如下所示:

export default {
  plugins: [
    'umi-plugin-react',
  ],
}

如果你在配置 umi-plugin-react 时传入了额外的参数,如下所示:

export default {
  plugins: [
    ['umi-plugin-react', { someOption: true }],
  ],
}

请确保你的参数是正确的对象形式,而不是数组形式。如果你需要传入多个插件参数,可以将它们放在一个对象中,如下所示:

export default {
  plugins: [
    ['umi-plugin-react', { someOption: true, anotherOption: 'foo' }],
    ['umi-plugin-something-else', { someOption: false }],
  ],
}

如果我的建议对您有帮助、请点击采纳、祝您生活愉快

以下答案由GPT-3.5大模型与博主波罗歌共同编写:
根据报错信息,错误是因为 umi-plugin-react 插件设置不合法导致的。您可以检查一下 config.js 文件中的插件设置是否正确。具体来讲,您可以尝试以下步骤:

  1. 确认 umi-plugin-react 的版本

检查一下您的 package.json 文件,确认您安装的 umi-plugin-react 的版本与当前项目所支持的 umi 版本兼容。

  1. 确认 umi-plugin-react 插件设置是否正确

检查一下您的 config.js 文件,确认您的 umi-plugin-react 插件设置是否正确。可以尝试将以下代码:

{
  "plugins": [
    [
      "umi-plugin-react",
      {
        antd: true,
        dva: true,
        dynamicImport: {
          loadingComponent: "./components/PageLoading/index"
        },
        title: "iConnect Web",
        dll: false,
        pwa: false,
        routes: {
          exclude: []
        },
        hardSource: false,
        locale: {
          enable: true,
          default: "en-US",
          baseNavigator: true
        }
      }
    ]
  ]
}

替换掉你的 config.js 文件中的 umi-plugin-react 配置试试看是否可以正常启动。

  1. 删除 node_modules 重新安装依赖

如果以上步骤无效,您可以尝试删除该项目的 node_modules 目录,然后重新运行 npm install 命令,再尝试启动项目。
如果我的回答解决了您的问题,请采纳!