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

Project cannot be build Cannot read properties of undefined (reading 'file') #25496

Closed
1 task done
ms270169 opened this issue Jul 6, 2023 · 36 comments
Closed
1 task done

Comments

@ms270169
Copy link

ms270169 commented Jul 6, 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

Building a new Angular 16.1.0 project via @angular/cli fails.
The project was not modified after creation!

Minimal Reproduction

$ npm -g install @angular/cli
...
$ ng version
...
Angular CLI: 16.1.3
Node: 16.19.0
Package Manager: npm 8.19.3
OS: linux x64

Angular: 
... 

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1601.3 (cli-only)
@angular-devkit/core         16.1.3 (cli-only)
@angular-devkit/schematics   16.1.3 (cli-only)
@schematics/angular          16.1.3 (cli-only)
$  ng new ngx
? Would you like to add Angular routing? Yes
? Which stylesheet format would you like to use? CSS
CREATE ngx/README.md (1057 bytes)
CREATE ngx/.editorconfig (274 bytes)
CREATE ngx/.gitignore (548 bytes)
CREATE ngx/angular.json (2685 bytes)
CREATE ngx/package.json (1034 bytes)
CREATE ngx/tsconfig.json (901 bytes)
CREATE ngx/tsconfig.app.json (263 bytes)
CREATE ngx/tsconfig.spec.json (273 bytes)
CREATE ngx/.vscode/extensions.json (130 bytes)
CREATE ngx/.vscode/launch.json (470 bytes)
CREATE ngx/.vscode/tasks.json (938 bytes)
CREATE ngx/src/main.ts (214 bytes)
CREATE ngx/src/favicon.ico (948 bytes)
CREATE ngx/src/index.html (289 bytes)
CREATE ngx/src/styles.css (80 bytes)
CREATE ngx/src/app/app-routing.module.ts (245 bytes)
CREATE ngx/src/app/app.module.ts (393 bytes)
CREATE ngx/src/app/app.component.css (0 bytes)
CREATE ngx/src/app/app.component.html (23115 bytes)
CREATE ngx/src/app/app.component.spec.ts (982 bytes)
CREATE ngx/src/app/app.component.ts (207 bytes)
CREATE ngx/src/assets/.gitkeep (0 bytes)
✔ Packages installed successfully.
...
$ cd ngx
$ npm run build

> ngx@0.0.0 build
> ng build

✔ Browser application bundle generation complete.

./node_modules/@angular/common/fesm2022/common.mjs - Error: Module build failed (from ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
TypeError: /tmp/ngx/node_modules/@angular/common/fesm2022/common.mjs: Cannot read properties of undefined (reading 'file')

./node_modules/@angular/platform-browser/fesm2022/platform-browser.mjs - Error: Module build failed (from ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
TypeError: /tmp/ngx/node_modules/@angular/platform-browser/fesm2022/platform-browser.mjs: Cannot read properties of undefined (reading 'file')

./node_modules/@angular/router/fesm2022/router.mjs - Error: Module build failed (from ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
TypeError: /tmp/ngx/node_modules/@angular/router/fesm2022/router.mjs: Cannot read properties of undefined (reading 'file')

Exception or Error

/node_modules/@angular/common/fesm2022/common.mjs - Error: Module build failed (from ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
TypeError: /tmp/ngx/node_modules/@angular/common/fesm2022/common.mjs: Cannot read properties of undefined (reading 'file')

./node_modules/@angular/platform-browser/fesm2022/platform-browser.mjs - Error: Module build failed (from ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
TypeError: /tmp/ngx/node_modules/@angular/platform-browser/fesm2022/platform-browser.mjs: Cannot read properties of undefined (reading 'file')

./node_modules/@angular/router/fesm2022/router.mjs - Error: Module build failed (from ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
TypeError: /tmp/ngx/node_modules/@angular/router/fesm2022/router.mjs: Cannot read properties of undefined (reading 'file')

Your Environment

Angular CLI: 16.1.3
Node: 16.19.0
Package Manager: npm 8.19.3
OS: linux x64

Angular: 
... 

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1601.3 (cli-only)
@angular-devkit/core         16.1.3 (cli-only)
@angular-devkit/schematics   16.1.3 (cli-only)
@schematics/angular          16.1.3 (cli-only)

Anything else relevant?

No response

@codingsamuel
Copy link

I have the same issue with Angular 14.

Maybe related to a babel dependecy which was uploaded an hour ago?

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Jul 6, 2023

This seems to be indeed caused by a change (intentional or not) in Babel which is breaking the Angular linker.

path.hub which is accessed in https://github.com/angular/angular/blob/5d11844a7c31df56d2b97e3aa6cd1a70b5fccc70/packages/compiler-cli/linker/babel/src/es2015_linker_plugin.ts#L40 appears to be undefined.

@CondensedMilk7
Copy link

I am experiencing the same issue.

Interestingly, I downgraded to angular 15 globally, and creating a new project results in the same build error.

versions in package.json:

  "dependencies": {
    "@angular/animations": "^15.2.0",
    "@angular/common": "^15.2.0",
    "@angular/compiler": "^15.2.0",
    "@angular/core": "^15.2.0",
    "@angular/forms": "^15.2.0",
    "@angular/platform-browser": "^15.2.0",
    "@angular/platform-browser-dynamic": "^15.2.0",
    "@angular/router": "^15.2.0",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.12.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^15.2.9",
    "@angular/cli": "~15.2.9",
    "@angular/compiler-cli": "^15.2.0",
    "@types/jasmine": "~4.3.0",
    "jasmine-core": "~4.5.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "typescript": "~4.9.4"
  }

@codingsamuel
Copy link

A temporary fix would be:

"@babel/generator": "7.22.5",
"@babel/parser": "7.22.5",
"@babel/traverse": "7.22.5"

@mbenzenhoefer
Copy link
Contributor

I have the same issue with v15.2.9

@alan-agius4 alan-agius4 added area: devkit/build-angular freq4: critical Happens to many users every day labels Jul 6, 2023
@alan-agius4 alan-agius4 changed the title New Angular 16.1.0 project cannot be build New Angular 16.1.0 project cannot be build Cannot read properties of undefined (reading 'file') Jul 6, 2023
@beohoang98
Copy link

I have same issue on ~14.2.0

@hambra
Copy link

hambra commented Jul 6, 2023

same here with v16 :(

@Rahul-kalsha
Copy link

Getting same issue in Angular 15.2.9

@meraj-markettime
Copy link

Getting same issue in Angular 15.2.9

image

@thaoula
Copy link

thaoula commented Jul 6, 2023

As suggested here -
babel/babel#15752

Can you try and add this to package.json
"overrides": {
"@babel/traverse": "7.22.6"
},

@thanoskoutr
Copy link

Getting the same issue with latest Angular v14 (14.2.12).

@hambra
Copy link

hambra commented Jul 6, 2023

live example for angular also failing with the same error
https://stackblitz.com/run?file=src%2Fapp%2Fapp.component.html

@alan-agius4 alan-agius4 changed the title New Angular 16.1.0 project cannot be build Cannot read properties of undefined (reading 'file') Project cannot be build Cannot read properties of undefined (reading 'file') Jul 6, 2023
@Alfxjx
Copy link

Alfxjx commented Jul 6, 2023

 WARN  deprecated @babel/traverse@7.22.7: [WARNING] Use 7.22.6 instead of 7.22.7, reason: babel/babel#15752

 use pnpm i and found this waring, use the overrides and it fixed

"overrides": {
  "@babel/traverse": "7.22.6"
},

@Sapython
Copy link

Sapython commented Jul 6, 2023

I am facing this issue too.

Checked this in v15 and v16

image

@VKAlwaysWin
Copy link

Same for us (latest Angular 13)

@prnkrawat
Copy link

I am also facing this issue while creating the new project.
angularissue

@VedantBTS
Copy link

I am also facing the same issue when I created new project but for older created projects the issue is not there.

@Isabelcasmot
Copy link

I have the same issue and I tried the :
"overrides": {
"@babel/traverse": "7.22.6"
},

on package.json but is not working

@vampirepapi
Copy link

I have the same issue and I tried the : "overrides": { "@babel/traverse": "7.22.6" },

on package.json but is not working

try deleting node_modules and npm install and then ng serve
it will work 👯‍♂️

@Isabelcasmot
Copy link

I tried tha also, the issue is still there :(

@VedantBTS
Copy link

I also tried by deleting node_modules and npm install and then ng serve, but it's not working for me too

@nicolo-ribaudo
Copy link

Wait 10 minutes, I'm releasing a Babel patch (7.22.8 of @babel/core and @babel/traverse) that hopefully fixes this.

@vampirepapi
Copy link

strange, worked for me btw

@vampirepapi
Copy link

image
image

@jcbuilds
Copy link

jcbuilds commented Jul 6, 2023

I'm also facing the same issue with Angular 15.1.6.

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Jul 6, 2023

This issue has been caused @babel/traverse@7.22.7, the Babel team has reverted the change that caused this bug via babel/babel#15754 and released a new version @babel/traverse@7.22.8. (Thanks @nicolo-ribaudo).

Please ensure to remove NPM "overrides" and Yarn "resolutions" from your package.json and sync the lock file. The easier way would be to delete node_modules, yarn.lock and package-lock.json.

$ rm -rf node_modules yarn.lock package-lock.json

Windows users:

npx rimraf -rf node_modules yarn.lock package-lock.json

If after the above you are are still encountering this problem and you are not using the public NPM repository, make sure that your NPM mirror is synced.

@lorenzo-ap

This comment was marked as outdated.

@officialhenryromero

This comment was marked as resolved.

@VedantBTS

This comment was marked as outdated.

@nicolo-ribaudo
Copy link

Babel 7.22.8 released -- the steps listed in the original issue description (#25496 (comment)) now succesfully create and build an Angular project.

Please make sure to update @babel/core and @babel/traverse to 7.22.8!

@Isabelcasmot

This comment was marked as resolved.

@ocombe
Copy link
Contributor

ocombe commented Jul 6, 2023

Babel 7.22.8 released -- the steps listed in the original issue description (#25496 (comment)) now succesfully create and build an Angular project.

Please make sure to update @babel/core and @babel/traverse to 7.22.8!

I can confirm that it works now with the new version of babel traverse (automatically installed, no need to change anything to the original config)

@alan-agius4

This comment was marked as resolved.

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Jul 6, 2023

Closing as this issue has been resolved upstream and confirmed that the fix works.
See: #25496 (comment).

@janpauldahlke
Copy link

janpauldahlke commented Jul 6, 2023

quick reaction. gj and ty

@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 Aug 12, 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