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 fails with Cannot redefine property: File using Node 20.6.0 #25782

Closed
1 task
Yogu opened this issue Sep 5, 2023 · 29 comments
Closed
1 task

Build fails with Cannot redefine property: File using Node 20.6.0 #25782

Yogu opened this issue Sep 5, 2023 · 29 comments

Comments

@Yogu
Copy link

Yogu commented Sep 5, 2023

Command

build

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

If you use Node 20.6.0 (released yesterday) to build an Angular 16 papp, the following error occurs:

TypeError: Cannot redefine property: File
    at Function.defineProperty (<anonymous>)
    at Object.<anonymous> (/home/user/my-project/node_modules/@angular/compiler-cli/node_modules/@babel/core/lib/index.js:7:8)

I know Node 20 is not officially supported at the moment and it's not yet in LTS, but it worked before (in 20.5.1) and maybe it's good too approach this issue early. The relevant changes in Node might get backported to node 18.

I also don't know yet if this is an issue in Node, babel or angular-cli. In either case, it might be good to have this as a tracking issue.

Also affects Angular 15 and Angular 17.0.0-next.0.

Minimal Reproduction

nvm install 20.6.0
nvm use 20.6.0
npx @angular/cli@latest new my-project # (using defaults)
cd my-project
npx ng build

Exception or Error

⠇ Generating browser application bundles (phase: building)...node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

TypeError: Cannot redefine property: File
    at Function.defineProperty (<anonymous>)
    at Object.<anonymous> (/home/user/my-project/node_modules/@angular/compiler-cli/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> (/home/user/my-project/node_modules/@angular/compiler-cli/node_modules/@babel/core/lib/config/helpers/config-api.js:16:9)
    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> (/home/user/my-project/node_modules/@angular/compiler-cli/node_modules/@babel/core/lib/config/files/configuration.js:48:18)
    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> (/home/user/my-project/node_modules/@angular/compiler-cli/node_modules/@babel/core/lib/config/files/index.js:73:22)
    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> (/home/user/my-project/node_modules/@angular/compiler-cli/node_modules/@babel/core/lib/index.js:184:14)
    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 cjsLoader (node:internal/modules/esm/translators:282:14)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:233:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:308:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:428:15)
    at async Object.customOptions (/home/user/my-project/node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js:49:64)
    at async Object.loader (/home/user/my-project/node_modules/babel-loader/lib/index.js:67:20)

Node.js v20.6.0

Your Environment

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 16.2.1
Node: 20.6.0 (Unsupported)
Package Manager: npm 9.8.1
OS: linux x64

Angular: 16.2.3
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1602.1
@angular-devkit/build-angular   16.2.1
@angular-devkit/core            16.2.1
@angular-devkit/schematics      16.2.1
@angular/cli                    16.2.1
@schematics/angular             16.2.1
rxjs                            7.8.1
typescript                      5.1.6
zone.js                         0.13.1

Warning: The current version of Node (20.6.0) is not supported by Angular.

Anything else relevant?

No response

@Yogu
Copy link
Author

Yogu commented Sep 5, 2023

nodejs/node#49497 sounds like it could cause this behavior. I noticed that the @babel/core/lib/index.js file is executed twice, and fails the second time because exports is already populated. That would match the behavior described in the node issue.

For the sake of completeness, here is the babel issue: babel/babel#15927

@JeanMeche
Copy link
Member

Hi, thanks for reporting this. As you mentioned this is an upstream issue for an unsupported version yet.

@JeanMeche JeanMeche closed this as not planned Won't fix, can't repro, duplicate, stale Sep 5, 2023
thenick775 pushed a commit to thenick775/gbajs3 that referenced this issue Sep 6, 2023
@scorpation
Copy link

scorpation commented Sep 6, 2023

the problem is the version of Node. downgrade it to 16.14.2

@lazybobcat
Copy link

lazybobcat commented Sep 6, 2023

I don't know if it helps but I had the same issue with Node v20.6.0 and NPM 9.8.1 but it was fixed by upgrading NPM to 10.0.0 for the same version of Node

Edit: my bad, Nx cache was involved and downgrading Node to v18.13.0 was what fixed the issue

@lmknav
Copy link

lmknav commented Sep 6, 2023

Just encountered this with the latest node on GitLab pages. Didnt happen before.

@e-oz
Copy link

e-oz commented Sep 6, 2023

This issue is not related to NPM and not even related to Angular CLI.
node 20.6 breaks Babel, Babel breaks Angular CLI.

@minikdev
Copy link

minikdev commented Sep 6, 2023

I had the same issue this morning on my dockerized React & Vite app.
Ekran Resmi 2023-09-06 13 07 38

I was using node:latest image in my Dockerfile. I checked the Node version of the latest tag is upgraded to v20.6 10 hours ago.
So I downgraded the node image to node:18-alpine3.17 and it works now. I believe the node.js team fix this soon.

@ogabz12345
Copy link

Mine still didn't work @minikdev even after changing the node image FROM node:18-alpine3.17 AS build

@minikdev
Copy link

minikdev commented Sep 6, 2023

@ogabz12345 I just tried to build it and it worked, you might need to rebuild your image,
you can use docker-compose up --build to rebuild it
Ekran Resmi 2023-09-06 13 45 02

@ogabz12345
Copy link

ogabz12345 commented Sep 6, 2023

@minikdev Did the exact same thing, still getting same error and it literally started this morning. I also use FROM nginx:latest as serve can this be an issue as well?

@fonzane
Copy link

fonzane commented Sep 6, 2023

I encountered the same issue. After switching in my Dockerfile from
FROM node as build
to
FROM node:18-alpine3.17 as build
the error is gone.

@Tyre88
Copy link

Tyre88 commented Sep 6, 2023

I had same issue and switched this in my Dockerfile:
FROM node:20-alpine AS build

to
FROM node:18-alpine3.17 AS build

and now it works fine!

@hhfrancois
Copy link

force node 20.5 fix the issues
Thx

@ogabz12345
Copy link

@hhfrancois FROM node:20.5 AS build ?

@ogabz12345
Copy link

Finally worked. used FROM node:18-alpine3.17 AS build

@mritalian
Copy link

Automated testing that would catch this is hard

@gilbertotoledo
Copy link

node:18-alpine3.17 AS build worked for me! Tks @minikdev !

@Alex-Lip-Video
Copy link

Replacing FROM node:20-alpine3.17 with FROM node:20.5-alpine3.17 worked for me. Thank you @hhfrancois and @lazybobcat 👍🏼

@mkabatek
Copy link

mkabatek commented Sep 6, 2023

Github actions fails for my project today and it worked yesterday. Downgraded to node 18 and it works fine.

TypeError: Cannot redefine property: File
    at Function.defineProperty (<anonymous>)
    at Object.<anonymous> (... /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> (... /node_modules/@babel/core/lib/config/helpers/config-api.js:16:9)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Run actions/setup-node@v3
Attempting to download 20...
Acquiring 20.6.0 - x64 from https://github.com/actions/node-versions/releases/download/20.6.0-60927[1](https://github.com/FieldSync/fieldsync-web/actions/runs/6103441625/job/16563842646#step:9:1)[50](https://github.com/FieldSync/fieldsync-web/actions/runs/6103441625/job/16563842646#step:9:51)08/node-20.6.0-linux-x64.tar.gz
Extracting ...
/usr/bin/tar xz --strip 1 --warning=no-unknown-keyword -C /home/runner/work/_temp/5c133a3b-27be-4e1d-bc75-0ca91dbffb58 -f /home/runner/work/_temp/5bc8e4d5-2a02-4a3b-88fb-d445f3f5612c
Adding to the cache ...
Environment details
  node: v20.6.0
  npm: 9.8.1
  yarn: 1.22.19
 

For anyone facing this problem using Github actions on a project change to

      - name: Use Node@18.x
        uses: actions/setup-node@v3
        with:
          node-version: 18

@dustinnewman
Copy link

On macOS using homebrew, you can fix this for now by installing the git HEAD for node (fixed by nodejs/node#49500) until the next version includes the fix:

brew unlink node
brew install --HEAD node

Note this makes node from scratch locally, which takes considerably longer than typical brew install.

@tdkehoe
Copy link

tdkehoe commented Sep 7, 2023

Switching from Node 20.6.0 to Node 18.17.1 fixed the problem for me. nvm makes it easy to change Node versions.

bkimminich added a commit to juice-shop/juice-shop that referenced this issue Sep 7, 2023
@dawidpstrak
Copy link

I had same issue. Punishment for using latest node version in Dockerfile :D

@nicolo-ribaudo
Copy link

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

SlashNephy added a commit to SlashNephy/.github that referenced this issue Sep 9, 2023
maxpatiiuk added a commit to maxpatiiuk/tetris-react that referenced this issue Sep 10, 2023
To hopefully fix the build issues

Node.js 20 and 18 don't work. Partially due to angular/angular-cli#25782
dvcol added a commit to dvcol/dvcol.github.io that referenced this issue Sep 10, 2023
dvcol added a commit to dvcol/dvcol.github.io that referenced this issue Sep 10, 2023
@marquessbr
Copy link

I had the same problem in a project and I tried with version 20, the project didn't compile with prayer or macumba, much less with voodoo, I had to downgrade to version 18 and then it worked.

@nicolo-ribaudo
Copy link

@marquessbr You can also use 20.6.1. Only 20.6.0 had this bug.

@marquessbr
Copy link

@marquessbr You can also use 20.6.1. Only 20.6.0 had this bug.

cool!
Thanks man, maybe I'll need to use a newer version of node because my professor is just giving classes about signals and NgRx, but since I'm using NVM, it's easy to migrate between versions when I need to.

@SSerg-dev
Copy link

@marquessbr You can also use 20.6.1. Only 20.6.0 had this bug.

thank you,
I have a problem like this.
It a realy work
👍

@PremVarma01
Copy link

Try changing you node version. I mean you can downgrade and try.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests