You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React项目编译报错TypeError: plugin is not a function求助

解决React项目编译报错:TypeError: plugin is not a function及@firebase/auth警告

核心报错处理(TypeError: plugin is not a function)

  • 清除全量缓存并重装依赖:
    执行以下命令彻底清理缓存与旧依赖:
    rm -rf node_modules package-lock.json yarn.lock
    npm cache clean --force
    npm install
    
  • 检查webpack插件引用正确性:
    查看项目配置文件(如base.js)中插件的导入与实例化代码:
    • 确认插件是否为默认导出:若使用CommonJS,需用const Plugin = require('plugin-name')而非解构导入;若用ES模块,需import Plugin from 'plugin-name'
    • 确认插件是否正确实例化:类类型插件需加new关键字,如new Plugin(options),而非直接传入Plugin

@firebase/auth source-map-loader警告处理

  • 降级source-map-loader至兼容版本:
    部分高版本source-map-loader与@firebase/auth的source map格式不兼容,执行:
    npm install source-map-loader@1.1.3 --save-dev
    
  • 排除@firebase/auth的source map处理:
    若为自定义webpack配置,在module.rules中给source-map-loader添加排除规则:
    module: {
      rules: [
        {
          test: /\.js$/,
          enforce: 'pre',
          use: ['source-map-loader'],
          exclude: /node_modules\/@firebase\/auth/
        }
      ]
    }
    
  • 若使用Create React App:
    安装react-app-rewired与customize-cra覆盖默认配置:
    npm install react-app-rewired customize-cra --save-dev
    
    创建config-overrides.js文件:
    const { override, adjustStyleLoaders } = require('customize-cra');
    module.exports = override(
      adjustStyleLoaders(loaders => {
        loaders.pre.forEach(loader => {
          if (loader.loader === 'source-map-loader') {
            loader.exclude = /node_modules\/@firebase\/auth/;
          }
        });
      })
    );
    
    修改package.json中的scripts:
    "scripts": {
      "start": "react-app-rewired start",
      "build": "react-app-rewired build",
      "test": "react-app-rewired test"
    }
    

内容的提问来源于stack exchange,提问作者Jai

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 05:07:22