Skip to content

Build issue: "Cannot redefine property: File" with Node.js 20.6.0 #14299

@simoneb

Description

@simoneb

Describe the bug

When running vite build in an application that worked fine on Node.js 20, before version 20.6.0 (released yesterday), and without anything else having changed, I now get this build error.

This also happens on a newly created app (see repro) so I suspect that the issue is caused by the Node.js version.

$ npm run build

> app@1.0.0 build
> npm run build -w chatbot-ui


> chatbot-ui@0.0.0 build
> vite build

failed to load config from N:\app\packages\chatbot-ui\vite.config.jserror during build:
TypeError: Cannot redefine property: File
    at Function.defineProperty (<anonymous>)
    at Object.<anonymous> (N:\app\node_modules\@babel\core\lib\index.js:7:8)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at Module.require (node:internal/modules/cjs/loader:1115:19)
    at require (node:internal/modules/helpers:130:18)
    at Object.<anonymous> (N:\app\node_modules\@babel\core\lib\config\helpers\config-api.js:16:9)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)

This is the vite.config.js file:

import path from 'path'
import { dirname } from 'path'
import { fileURLToPath } from 'url'
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

const __dirname = dirname(fileURLToPath(import.meta.url))

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src')
    }
  },
  server: {
    proxy: {
      '/api': 'http://localhost:3000'
    }
  }
})

Reproduction

$ npm create vite@latest
√ Project name: ... vite-project
√ Select a framework: » React
√ Select a variant: » JavaScript

Scaffolding project in N:\temp\vite-project...

Done. Now run:

  cd vite-project
  npm install
  npm run dev

$ npm i
$ npm run build

> vite-project@0.0.0 build
> vite build

failed to load config from N:\temp\vite-project\vite.config.js
error during build:
TypeError: Cannot redefine property: File
    at Function.defineProperty (<anonymous>)
    at Object.<anonymous> (N:\temp\vite-project\node_modules\@babel\core\lib\index.js:7:8)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at Module.require (node:internal/modules/cjs/loader:1115:19)
    at require (node:internal/modules/helpers:130:18)
    at Object.<anonymous> (N:\temp\vite-project\node_modules\@babel\core\lib\config\helpers\config-api.js:16:14)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)

Steps to reproduce

No response

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Core(TM) i7-4720HQ CPU @ 2.60GHz
    Memory: 2.45 GB / 15.89 GB
  Binaries:
    Node: 20.6.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\.yarn\bin\yarn.CMD
    npm: 9.8.1 - C:\Program Files\nodejs\npm.CMD

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions