This error message indicates a problem with the Vite configuration file, particularly when using the 'vite-plugin-alias' package. The error message advises switching from the 'require' statement in your configuration file to a dynamic 'import()' statement, which is compatible with all CommonJS modules.

To resolve this, you can modify the 'require' statement in your 'vite.config.js' file to utilize a dynamic 'import()' statement instead.

For instance, instead of:

const { defineConfig } = require('vite')
const alias = require('vite-plugin-alias')

module.exports = defineConfig({
  plugins: [
    alias({
      entries: {
        '@': './src'
      }
    })
  ]
})

Try this:

const { defineConfig } = require('vite')

module.exports = defineConfig({
  plugins: [
    import('vite-plugin-alias').then(({ default: alias }) => alias({
      entries: {
        '@': './src'
      }
    }))
  ]
})

This adjustment should allow Vite to successfully load the configuration file and initiate the development server.

Vite Dev Server Error: ERR_REQUIRE_ESM - vite-plugin-alias Issue

原文地址: https://www.cveoy.top/t/topic/jxgE 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录