跳到主要内容

旧版浏览器支持

Reactive Data Client 的设计目标是开箱即用地适配大多数工具链。

如果你看到 Uncaught TypeError: Class constructor Resource cannot be invoked without 'new',这很可能是因为自定义的 webpack 配置以支持 Internet Explorer 为目标。即使使用的是现代浏览器也会出现这种情况,只要你的目标(通常通过 browserslist 设置)包含了 Internet Explorer 之类的旧版浏览器。

这种情况下,请按照下面的说明确保兼容性。

转译依赖包​

添加 webpack-plugin-modern-npm 可以确保所有已安装的依赖包都与旧版浏览器兼容。

npm install --save-dev webpack-plugin-modern-npm

然后在 webpack 配置中添加该插件。

webpack.config.js
const ModernNpmPlugin = require('webpack-plugin-modern-npm');

module.exports = {
plugins: [
new ModernNpmPlugin()
]
};

Polyfills​

使用 CRA polyfill 或按照下面的说明操作。

npm install --save core-js whatwg-fetch
index.tsx
import 'core-js/stable';
import 'whatwg-fetch';
// place the above line at top