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

Angular never searches for zone.js in the correct path #27473

Open
1 task done
its-dibo opened this issue Apr 16, 2024 · 6 comments
Open
1 task done

Angular never searches for zone.js in the correct path #27473

its-dibo opened this issue Apr 16, 2024 · 6 comments
Labels
needs: discussion On the agenda for team meeting to determine next steps

Comments

@its-dibo
Copy link

its-dibo commented Apr 16, 2024

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

I have a monorepo, one of its workspaces is an Angular workspace. and I use pnpm to install the dependencies
each workspace has its own node_modules folder.

when I start building this app (the Angular workspace), it fails to find zone.js
it should find it inside node_modules of the Angular app

this debug info may be useful
as you can see it looks in:

  • dibo/node_modules/zone.js (the monorepo's top-level root)
  • dibo/apps/mobarmegeen/mobarmegeen-ui/zone.js

but never looks in the correct path which is dibo/apps/mobarmegeen/mobarmegeen-ui/node_modules/zone.js

debug info
 [DEBUG] Resolving import "zone.js/node" in directory "/home/dibo/dev/@its-dibo/dibo" of type "import-statement"

  Checking for package alias matches
    Failed to find any package alias matches
  Read 25 entries for directory "/"
  Read 1 entry for directory "/home"
  Read 25 entries for directory "/home/dibo"
  Read 4 entries for directory "/home/dibo/dev"
  Read 3 entries for directory "/home/dibo/dev/@its-dibo"
  The file "/home/dibo/dev/@its-dibo/dibo/package.json" exists
  Read 40 entries for directory "/home/dibo/dev/@its-dibo/dibo"
  Read 40 entries for directory "/home/dibo/dev/@its-dibo/dibo"
  Searching for "zone.js/node" in "node_modules" directories starting from "/home/dibo/dev/@its-dibo/dibo"
    Matching "zone.js/node" against "paths" in
  "/home/dibo/dev/@its-dibo/dibo/apps/mobarmegeen/mobarmegeen-ui/tsconfig.app.json"
      Using "/home/dibo/dev/@its-dibo/dibo/apps/mobarmegeen/mobarmegeen-ui" as "baseURL"
    Attempting to load "/home/dibo/dev/@its-dibo/dibo/apps/mobarmegeen/mobarmegeen-ui/zone.js/node" as a file
      Failed to read directory "/home/dibo/dev/@its-dibo/dibo/apps/mobarmegeen/mobarmegeen-ui/zone.js": open
  /home/dibo/dev/@its-dibo/dibo/apps/mobarmegeen/mobarmegeen-ui/zone.js: no such file or directory
    Attempting to load "/home/dibo/dev/@its-dibo/dibo/apps/mobarmegeen/mobarmegeen-ui/zone.js/node" as a directory
      Read 40 entries for directory "/home/dibo/dev/@its-dibo/dibo"
      Read 2 entries for directory "/home/dibo/dev/@its-dibo/dibo/apps"
      Read 2 entries for directory "/home/dibo/dev/@its-dibo/dibo/apps/mobarmegeen"
      The file "/home/dibo/dev/@its-dibo/dibo/apps/mobarmegeen/mobarmegeen-ui/package.json" exists
      Read 16 entries for directory "/home/dibo/dev/@its-dibo/dibo/apps/mobarmegeen/mobarmegeen-ui"
      Failed to read directory "/home/dibo/dev/@its-dibo/dibo/apps/mobarmegeen/mobarmegeen-ui/zone.js": open
  /home/dibo/dev/@its-dibo/dibo/apps/mobarmegeen/mobarmegeen-ui/zone.js: no such file or directory
      Failed to read directory "/home/dibo/dev/@its-dibo/dibo/apps/mobarmegeen/mobarmegeen-ui/zone.js"
      Failed to read directory "/home/dibo/dev/@its-dibo/dibo/apps/mobarmegeen/mobarmegeen-ui/zone.js/node"
    Parsed package name "zone.js" and package subpath "./node"
    Checking for a package in the directory "/home/dibo/dev/@its-dibo/dibo/node_modules/zone.js/node"
    Read 40 entries for directory "/home/dibo/dev/@its-dibo/dibo"
    Read 76 entries for directory "/home/dibo/dev/@its-dibo/dibo/node_modules"
    Failed to read directory "/home/dibo/dev/@its-dibo/dibo/node_modules/zone.js": open
  /home/dibo/dev/@its-dibo/dibo/node_modules/zone.js: no such file or directory
    Failed to read directory "/home/dibo/dev/@its-dibo/dibo/node_modules/zone.js"
    Attempting to load "/home/dibo/dev/@its-dibo/dibo/node_modules/zone.js/node" as a file
      Failed to read directory "/home/dibo/dev/@its-dibo/dibo/node_modules/zone.js": open
  /home/dibo/dev/@its-dibo/dibo/node_modules/zone.js: no such file or directory
    Attempting to load "/home/dibo/dev/@its-dibo/dibo/node_modules/zone.js/node" as a directory
      Failed to read directory "/home/dibo/dev/@its-dibo/dibo/node_modules/zone.js"
      Failed to read directory "/home/dibo/dev/@its-dibo/dibo/node_modules/zone.js/node"

✘ [ERROR] Could not resolve "zone.js/node"

    angular:polyfills-server:angular:polyfills-server:1:7:
      1 │ import 'zone.js/node';
        ╵        ~~~~~~~~~~~~~~

  You can mark the path "zone.js/node" as external to exclude it from the bundle, which will remove
  this error and leave the unresolved path in the bundle.

Minimal Reproduction

https://github.com/its-dibo/issue-zonejs

1- install via pnpm pnpm install
if pnpm is not installed, simply, run npm I -g pnpm

2- run the app npm start

note: don't use any other package manager, as they hoist the packages of the app to the root of the monorepo.
.

Exception or Error

No response

Your Environment

Angular CLI: 17.0.3
Node: 20.10.0
Package Manager: yarn 1.22.22
OS: linux x64

Angular: undefined
... 

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1700.3 (cli-only)
@angular-devkit/core         17.0.3 (cli-only)
@angular-devkit/schematics   17.0.3 (cli-only)
@schematics/angular          17.0.3 (cli-only)
rxjs   


@alan-agius4
Copy link
Collaborator

Polyfills are resolved from the workspace root because they're referenced in the angular.json file. Typically, in an Angular CLI workspace, it's expected to have a single node_modules directory at the top level of the workspace.

@alan-agius4 alan-agius4 added the needs: more info Reporter must clarify the issue label Apr 16, 2024
@its-dibo
Copy link
Author

its-dibo commented Apr 16, 2024

Polyfills are resolved from the workspace root

that is what I need, but the actual behavior is that it searches in the monorepo's root rather than the workspace's root.

note that the Angular workspace is part of a monorepo.

@alan-agius4
Copy link
Collaborator

Can you setup a minimal repro please?

You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

This might be related to your directory structure so its really important to get an accurate repro to diagnose this.

@alan-agius4 alan-agius4 added needs: repro steps We cannot reproduce the issue with the information given and removed needs: more info Reporter must clarify the issue labels Apr 17, 2024
@its-dibo
Copy link
Author

Can you setup a minimal repro please?

I updated the description with the minimal repro and steps to reproduction

@alan-agius4
Copy link
Collaborator

Hello @its-dibo, thank you for your reproduction. It seems that this is an NX managed monorepo, so its operation differs slightly from an Angular CLI workspace due to the presence of multiple nested projects.json and an nx.json file. In an NX monorepo, however the workspace root is where your nx.json is located, so the polyfills and other node_modules entries are resolved relative to that location.

@its-dibo
Copy link
Author

but, as you know, pnpm creates s node_module folder for each package separately (hard links)
that's mean that polyfills can never be found, as they'll never be presents in the same level of nx.json

@alan-agius4 alan-agius4 added needs: discussion On the agenda for team meeting to determine next steps and removed needs: repro steps We cannot reproduce the issue with the information given labels Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: discussion On the agenda for team meeting to determine next steps
Projects
None yet
Development

No branches or pull requests

2 participants