Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

开启 module federation 后 在低版本浏览器下报错! #5969

Closed
ckken opened this issue Mar 19, 2024 · 7 comments · Fixed by #6672
Closed

开启 module federation 后 在低版本浏览器下报错! #5969

ckken opened this issue Mar 19, 2024 · 7 comments · Fixed by #6672
Assignees
Labels
bug Something isn't working

Comments

@ckken
Copy link

ckken commented Mar 19, 2024

.split(/(?<=[-0-9A-Za-z])\s+/g)

  • 开启 mf 为 1.0
  • uagent Mozilla/5.0 (Linux; U; Android 7.1.1; zh-cn; MI 6 Build/NMF26X) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.146 Mobile Safari/537.36 XiaoMi/MiuiBrowser/9.2.11
  • 报错 ​ Uncaught SyntaxError: Invalid regular expression: /(?<=[-0-9A-Za-z])\s+/: Invalid group
@ahabhgk
Copy link
Collaborator

ahabhgk commented Mar 21, 2024

Since you already find the cause, would you want to send a PR?

@h-a-n-a h-a-n-a added bug Something isn't working and removed pending triage The issue/PR is currently untouched. labels Mar 21, 2024
@ckken
Copy link
Author

ckken commented Mar 22, 2024

#6002 解决 module federation 1.0 正则
目前 1.5 也有兼容性问题 还在定位

@ckken
Copy link
Author

ckken commented Mar 22, 2024

image
1.5 的问题大概率是 mf runtime 没走编译直接输出 导致一系列兼容性问题 希望可以根据系统进行兼容性编译

@wzc321
Copy link

wzc321 commented May 16, 2024

确实是的,没走编译,导致里面大量let、箭头函数

@chenjiahan
Copy link
Member

Related issue in Rsbuild: web-infra-dev/rsbuild#2360 (will be fixed in the next version)

For Rspack users, you can add the following Rspack rule to match the virtual modules created by the ModuleFederationPlugin:

// rspack.config.js
module.exports = {
  module: {
    rules: [
      {
        mimetype: {
          or: [
            'text/javascript',
            'application/node',
            'application/javascript'
          ]
        },
        use: [
          {
            loader: 'builtin:swc-loader',
            options: {
              // some SWC options
            }
          }
        ],
      },
    ]
  },
}

@2heal1
Copy link
Member

2heal1 commented May 20, 2024

for rspack, you can add below configuration to downgrade @module-federation/runtime :

// rspack.config.js
  module: {
    rules:[
      {
+        mimetype: {
+          or: [
+           'text/javascript',
+           'application/node',
+            'application/javascript'
+          ]
+        },
        use: {
          loader: 'builtin:swc-loader',
          options: {
+           env: {
+            targets: [
+               "> 0.5%",
+              "not dead",
+               "IE 11"
+             ],
            },
            jsc: {
              parser: {
                syntax: 'ecmascript',
                jsx: true,
              },
              transform: {
                react: {
                  pragma: 'React.createElement',
                  pragmaFrag: 'React.Fragment',
                  throwIfNamespace: true,
                  development: false,
                  useBuiltins: false,
                },
              },
          
            },
          },
        },
        type: 'javascript/auto',
      },
      {
        test: /\.jsx?$/,
        use: {
          loader: 'builtin:swc-loader',
          options: {
+           env: {
+              targets: [
+               "> 0.5%",
+              "not dead",
+               "IE 11"
+            ],
            },
            jsc: {
              parser: {
                syntax: 'ecmascript',
                jsx: true,
              },
              transform: {
                react: {
                  pragma: 'React.createElement',
                  pragmaFrag: 'React.Fragment',
                  throwIfNamespace: true,
                  development: false,
                  useBuiltins: false,
                },
              },
          
            
            },
          },
        },
        type: 'javascript/auto',
      },
    ]
  },

I recommend you use rsbuild , it will auto apply you targets , no need to config so complex. And the [email protected] will be release this week

@wzc321
Copy link

wzc321 commented May 20, 2024

Thanks, I prefer to use Rsbuild and I will wait for the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants