Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
7 tasks done
simoneb opened this issue Sep 5, 2023 · 9 comments
Closed
7 tasks done

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

simoneb opened this issue Sep 5, 2023 · 9 comments

Comments

@simoneb
Copy link

simoneb commented Sep 5, 2023

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

@simoneb
Copy link
Author

simoneb commented Sep 5, 2023

Ok I see that the issue is already in Babel babel/babel#15927

@bluwy
Copy link
Member

bluwy commented Sep 5, 2023

Yeah it is an upstream issue in node, there's not much we can do so closing for now. It's affecting many other projects so hope it should be fixed soon.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Sep 5, 2023
daviwil added a commit to microsoft/typespec that referenced this issue Sep 6, 2023
It looks like CI is failing due to an issue with Babel.js conflicting
with Node 20.6:

babel/babel#15927
vitejs/vite#14299

For now, let's try pinning Node 20.x to 20.5 until the issue gets fixed
in Babel.

Comparable `typespec-azure` repo PR:
https://github.com/Azure/typespec-azure/pull/3502

Issue https://github.com/Azure/typespec-azure/issues/3504 tracks the
work to un-pin the Node version.
vikunja-bot pushed a commit to go-vikunja/frontend that referenced this issue Sep 6, 2023
clemlesne added a commit to clemlesne/private-gpt that referenced this issue Sep 8, 2023
…conversation-ui/develop/library/node-b46062a"

This reverts commit 23cf329.

Vite.js is bugged: vitejs/vite#14299
@nicolo-ribaudo
Copy link

We added a workaround for this in @babel/core, @babel/traverse and @babel/types 7.22.17

@simoneb
Copy link
Author

simoneb commented Sep 8, 2023

Thanks @nicolo-ribaudo, too bad that the Node fix has been slow to come, appreciate you coming up with a workaround.

@zengxs
Copy link

zengxs commented Sep 15, 2023

Upgrading NodeJS to 20.6.1 will fix this issue.

@yahyaemre
Copy link

same issue, fix with upgrading Node

@myrojoylee
Copy link

Had the same issue and upgraded to 20.7.0 in order for it to work.

@tkostas15
Copy link

Upgrading NodeJS to 20.6.1 will fix this issue.

That fixed the issue to me, thanks !

@ashishsingh10
Copy link

The issue has been resolved! Just updated the Node version from 20.6.0 to 20.7.0

@github-actions github-actions bot locked and limited conversation to collaborators Oct 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants