Quise hacer un build de aplicación Vite + React, el build sale bien pero cuando hago npm run preview, no funciona.
vite.config.js
import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"
import commonjs from '@rollup/plugin-commonjs';
export default defineConfig(async () => {
const mdx = await import("@mdx-js/rollup")
return {
optimizeDeps: {
include: ["react/jsx-runtime"],
},
plugins: [react(), mdx.default({ remarkPlugins: [] }), commonjs(), external({
includeDependencies: true
}),],
}
})
ERROR: Uncaught TypeError: Failed to resolve module specifier "vite/modulepreload-polyfill". Relative references must start with either "/", "./", or "../".
Prueba solución Siguiendo: https://vitejs.dev/config/build-options#build-polyfillmodulepreload
import external from "rollup-plugin-peer-deps-external";
import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"
import commonjs from '@rollup/plugin-commonjs';
export default defineConfig(async () => {
const mdx = await import("@mdx-js/rollup")
return {
optimizeDeps: {
include: ["react/jsx-runtime"],
},
plugins: [react(), mdx.default({ remarkPlugins: [] }), commonjs(), external({
includeDependencies: true
}),],
build: {
polyfillModulePreload: false
}
}
})
Nuevo ERROR: Uncaught TypeError: Failed to resolve module specifier "react/jsx-runtime". Relative references must start with either "/", "./", or "../".