Vite build failed on project with aws-sdk
Lumin

Lumin @ilumin

Location:
Bangkok, Thailand
Joined:
Jan 25, 2018

Vite build failed on project with aws-sdk

Publish Date: Apr 25 '22
8 2

Vite work greate on local development.

But I got this error when build.

'request' is not exported by __vite-browser-external, imported by node_modules/@aws-sdk/credential-provider-node/node_modules/@aws-sdk/credential-provider-imds/dist/es/remoteProvider/httpRequest.js
Enter fullscreen mode Exit fullscreen mode

The solution is put some script on index.html

<script>
var global = global || window
var Buffer = Buffer || []
var process = process || { env: { DEBUG: undefined }, version: [] }
</script>
Enter fullscreen mode Exit fullscreen mode

And that's it, all sorted! 😛

Thanks community.

Comments 2 total

  • Wesley Cheek
    Wesley CheekJun 24, 2022

    Thanks, but unfortunately this didn't work for me but this fix did:

    In vite.config.js add:

    resolve: {
      alias: {
       './runtimeConfig': './runtimeConfig.browser',
      },
    }
    

    in define field

    So my vite.config.js looks like this:

    import { fileURLToPath, URL } from "url";
    
    import { defineConfig } from "vite";
    import vue from "@vitejs/plugin-vue";
    
    // https://vitejs.dev/config/
    export default defineConfig({
      plugins: [vue()],
      resolve: {
        alias: {
          "./runtimeConfig": "./runtimeConfig.browser",
          "@": fileURLToPath(new URL("./src", import.meta.url)),
        },
      },
    });
    
    Enter fullscreen mode Exit fullscreen mode
  • Aneesha Jenson
    Aneesha JensonMay 6, 2024

    Uncaught TypeError: t is not a constructor

    Iam also facing this kind of issues when using aws-sdk with vite.js . Iam facing this above type of error.

Add comment