shadcn-ui / ui

Beautifully designed components that you can copy and paste into your apps. Accessible. Customizable. Open Source.
https://ui.shadcn.com
MIT License
72.49k stars 4.4k forks source link

[bug] — TypeError: Cannot redefine property: File #3936

Open piousdev opened 4 months ago

piousdev commented 4 months ago

Describe the bug

TypeError: Cannot redefine property: File

Description

I encountered a TypeError: Cannot redefine property: File when trying to initialize shadcn-ui in my Next.js project. This issue occurs despite not using Babel directly in my project. Below are the details of the environment and steps to reproduce the issue.

I have cleared the npm cache, deleted node_modules, completely deleted Node.js and all it traces and reinstalling it again. This issue does not occur when Babel is explicitly added to the project. This issue persists across different Node.js versions and across different projects.

I try isolating it by starting out a new test-project and still the same issue.

Affected component/components

All. Can't initialize shadcn.

How to reproduce

  1. Create a new Next.js project: npx create-next-app@latest --typescript my-app && cd my-app

  2. Initialize shadcn-ui: npx shadcn-ui@latest init

Codesandbox/StackBlitz link

No response

Logs

Error Output:
Need to install the following packages:
shadcn-ui@0.8.0
Ok to proceed? (y) y

/Users/username/.npm/_npx/125ee17d583c4e03/node_modules/@babel/core/lib/index.js:7
Object.defineProperty(exports, "File", {
       ^

TypeError: Cannot redefine property: File
    at Function.defineProperty (<anonymous>)
    at Object.<anonymous> (/Users/username/.npm/_npx/125ee17d583c4e03/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> (/Users/username/.npm/_npx/125ee17d583c4e03/node_modules/@babel/core/lib/config/helpers/config-api.js:16:14)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)

Node.js v20.6.0

Indicating Node.js v20.6.0 despite using the currently LTS version Node.js v20.14.0

System Info

#### Environment
- **Node.js Version**: v20.14.0
- **npm Version**: 10.8.1
- **npx Version**: Installed with npm 10.8.1
- **Operating System**: macOS 13 inch M1 2020 - macOS somoma v14.5

Before submitting

PranitPatil03 commented 4 months ago

hey @piousdev 👋

I tried to reproduce this but this is not a bug, according to your command npx create-next-app@latest --typescript my-app && cd my-app instead of this you can used npx create-next-app@latest my-app --typescript cd my-app

t3dotgg commented 1 month ago

I had this issue as well, ended up being specific to using Node version 20.6.0. When I bumped my project to latest it worked as expected