I am currently facing an issue while deploying my Vite-based React application to AWS using GitHub Actions. The deployment process completes successfully, but when I try to run the application, I encounter the following error in the browser console: "Uncaught Error: Service firestore is not available".
I am using this vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import viteTsconfigPaths from 'vite-tsconfig-paths'
import commonjs from '@rollup/plugin-commonjs';
export default defineConfig({
// depending on your application, base can also be "/"
base: '',
resolve: {
alias: {
'aws-sdk': 'aws-sdk/dist/aws-sdk.min.js',
},
},
define: {
global: 'globalThis',
},
plugins: [react(), viteTsconfigPaths(), updateCommonjsPlugin()],
server: {
// this ensures that the browser opens upon server start
open: true,
// this sets a default port to 3000
port: 3000,
watch: {
followSymlinks: false,
},
},
build: {
minify: false,
sourcemap: false,
},
})
function updateCommonjsPlugin(): import('vite').PluginOption {
const commonJs22 = commonjs({
include: [/node_modules/],
extensions: ['.js', '.cjs'],
strictRequires: true,
})
return {
name: 'new-common-js',
apply: 'build',
config: (config) => {
return {
...config,
plugins: [...(config.plugins || []), commonJs22],
}
},
}
}
Need help and thanks in advance.
The CJS build of Vite's Node API is deprecated. You should update your files or frameworks to import the ESM build of Vite instead.
In a basic Vite project, make sure:
The vite.config.js file content is using the ESM syntax. The closest package.json file has "type": "module", or use the .mjs/.mts extension, e.g. vite.config.mjs or vite.config.mts.
If the package.json does not contain "type": "module", Vite will generate different file extensions for Node.js compatibility. .js will become .mjs and .cjs will become .js.