使用 aws-sdk 构建 Vite 失败 - 未捕获类型错误:无法读取未定义的属性(读取“原型”)

Rav*_*thz 5 amazon-s3 typescript reactjs aws-sdk vite

我收到以下错误,而不是检查发现的错误 - AWS$6.STS.prototype Uncaught TypeError: Cannot read properties of undefined (reading 'prototype')

就构建成功了。我可以将文件上传到 aws s3。

小智 0

发生这种情况是因为 vite 内的 rollup 版本需要更新到 v22。

目前有一个解决方法:

export const updateCommonjsPlugin = (): Plugin => {
  const commonJs22 = commonjs({
    include: [/node_modules/],
    extensions: [".js", ".cjs"],
    strictRequires: true,
  });

  return {
    name: "new-common-js",
    options(rawOptions) {
      const plugins = Array.isArray(rawOptions.plugins)
        ? [...rawOptions.plugins]
        : rawOptions.plugins
        ? [rawOptions.plugins]
        : [];

      const index = plugins.findIndex(
        (plugin) => plugin && plugin.name === "commonjs"
      );
      if (index !== -1) {
        plugins.splice(index, 1, commonJs22);
      }

      const nextConfig = { ...rawOptions, plugins };
      return commonJs22.options.call(this, nextConfig);
    },
  };
};
Run Code Online (Sandbox Code Playgroud)

并将vite.config.ts其添加到插件中

plugins: [updateCommonjsPlugin()],
Run Code Online (Sandbox Code Playgroud)

有关此内容的更多信息,请参阅此 GH 线程