umijs / umi

A framework in react community ✨
https://umijs.org
MIT License
15.4k stars 2.66k forks source link

[Bug] 开启mfsu后浏览器报错:jsonpScript is not defined #7212

Closed liyaxuanliyaxuan closed 2 years ago

liyaxuanliyaxuan commented 3 years ago

What happens?

开启mfsu后浏览器报错:jsonpScript is not defined image

image

相关配置

`const config: IConfig = { history: { type: 'hash' }, exportStatic: false, mountElementId: 'app',

// ref: https://umijs.org/plugin/umi-plugin-react.html

antd: { dark: false, }, dva: { immer: true, }, title: '资源库', dynamicImport: {},

routes, alias: { '@': path.resolve(__dirname, './src'), },

chainWebpack: umiChainWebpack, extraBabelPlugins: ['babel-plugin-styled-components'], externals: externals, theme, devServer: devServerConfig, proxy, webpack5: {}, mfsu: {}, };`

How To Reproduce

Steps to reproduce the behavior: 1. 2.

Expected behavior 1. 2.

Context

sorrycc commented 3 years ago

如果确定是 mfsu 开启后的问题,需要给复现。

liyaxuanliyaxuan commented 3 years ago

升级umi3的相关记录

  1. 版本修改并安装

    1. umi
    2. @umi-plugin-react
  2. 修改.umirc.ts配置

    npm start产生报错

image

安装alife-logger后无报错

  1. webpack 打包运行正常

    1. 若不使用mfsu

image

  https://localhost:1024 可以正常访问
  1. 若开启 浏览器报错jsonpScriptSrc is not defined

image image

  webpack运行正常

image

  1. 目前配置如下:

    export default defineConfig({
     history: { type: 'hash' },
     exportStatic: false,
     mountElementId: 'dingapp',
    
     // ref: https://umijs.org/plugin/umi-plugin-react.html
    
     antd: {
       dark: false,
     },
     dva: {
       immer: true,
     },
     title: '资源库',
     dynamicImport: {},
     nodeModulesTransform: {
       type: 'none',
     },
     routes,
     alias: {
       '@': path.resolve(__dirname, './src'),
     },
    
     chainWebpack: umiChainWebpack,
     extraBabelPlugins: ['babel-plugin-styled-components'],
     externals: externals,
     theme,
     devServer: devServerConfig,
     proxy,
     mfsu: {},
     // webpack5: {},
    });
    
liyaxuanliyaxuan commented 3 years ago

我也遇到同样的错误

你也是升级后开启吗?

sorrycc commented 3 years ago

@liyaxuanliyaxuan

两个问题,

  1. chainWebpack 里的处理不要针对 mfsu 生效,
- const umiChainWebpack: IConfig['chainWebpack'] = (config) => {
+ const umiChainWebpack: IConfig['chainWebpack'] = (config, { mfsu }) => {
+   if (mfsu) return;
  1. alife-logger@1.8.11 里的 exports 属性有问题,他们已在 1.8.30 里修复了,需要做的是推动 @ali/we-logger 升级前者到依赖
sorrycc commented 3 years ago

@chzng 你肯定不是相同问题。

sorrycc commented 3 years ago

太多太多太多人反馈这个mfsu开启的问题了,肯定有问题

有 bug,但基本都不是关键 bug,内网 700+ 项目在用。

liyaxuanliyaxuan commented 3 years ago

感谢 @sorrycc 。目前删除 chainwebpack 的配置,项目运行正常,浏览器无报错。但是增加 chainWebpack 对

@liyaxuanliyaxuan

两个问题,

  1. chainWebpack 里的处理不要针对 mfsu 生效,
- const umiChainWebpack: IConfig['chainWebpack'] = (config) => {
+ const umiChainWebpack: IConfig['chainWebpack'] = (config, { mfsu }) => {
+   if (mfsu) return;
  1. alife-logger@1.8.11 里的 exports 属性有问题,他们已在 1.8.30 里修复了,需要做的是推动 @ali/we-logger 升级前者到依赖

感谢 @sorrycc 。目前删除 chainwebpack 的配置,项目运行正常,浏览器无报错。但是增加 chainWebpack 配置,按照上面的修改方式,还是会产生同样的报错。