DEV Community

Teerasak Vichadee
Teerasak Vichadee

Posted on

Vite build failed on project with aws-sdk

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

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

And that's it, all sorted! 😛

Thanks community.

Top comments (2)

wesleycheek profile image
Wesley Cheek

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";

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      "./runtimeConfig": "./runtimeConfig.browser",
      "@": fileURLToPath(new URL("./src", import.meta.url)),
Enter fullscreen mode Exit fullscreen mode
aneeshahib profile image
Aneesha Jenson

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.