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

cannot resolve polyfills #22847

Open
1 of 4 tasks
its-dibo opened this issue Apr 16, 2024 · 0 comments
Open
1 of 4 tasks

cannot resolve polyfills #22847

its-dibo opened this issue Apr 16, 2024 · 0 comments
Assignees
Labels
scope: angular Issues related to Angular support in Nx type: bug

Comments

@its-dibo
Copy link

its-dibo commented Apr 16, 2024

Current Behavior

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

apps/mobarmegeen/mobarmegeen-ui/project.json
{
  "$schema": "node_modules/nx/schemas/project-schema.json",
  "name": "mobarmegeen-ui",
  "projectType": "application",
  "generators": {
    "@schematics/angular:component": {
      "style": "scss"
    }
  },
  "sourceRoot": "apps/mobarmegeen/mobarmegeen-ui/src",
  "prefix": "app",
  "targets": {
    "build": {
      "executor": "@angular-devkit/build-angular:application",
      "outputs": ["{options.outputPath}"],
      "options": {
        "outputPath": "apps/mobarmegeen/mobarmegeen-ui/dist",
        "index": "apps/mobarmegeen/mobarmegeen-ui/src/index.html",
        "browser": "apps/mobarmegeen/mobarmegeen-ui/src/main.ts",
        "polyfills": ["zone.js"],
        "tsConfig": "apps/mobarmegeen/mobarmegeen-ui/tsconfig.app.json",
        "inlineStyleLanguage": "scss",
        "assets": [
          "apps/mobarmegeen/mobarmegeen-ui/src/favicon.ico",
          "apps/mobarmegeen/mobarmegeen-ui/src/assets",
          "apps/mobarmegeen/mobarmegeen-ui/src/manifest.webmanifest",
          "apps/mobarmegeen/mobarmegeen-ui/src/scripts.mjs",
          "apps/mobarmegeen/mobarmegeen-ui/src/configs"
        ],
        "styles": [
          "@angular/material/prebuilt-themes/indigo-pink.css",
          "apps/mobarmegeen/mobarmegeen-ui/src/styles.scss",
          "quill/dist/quill.core.css",
          "quill/dist/quill.bubble.css",
          "quill/dist/quill.snow.css"
        ],
        "scripts": [],
        "server": "apps/mobarmegeen/mobarmegeen-ui/src/main.server.ts",
        "prerender": false,
        "ssr": {
          "entry": "apps/mobarmegeen/mobarmegeen-ui/server.ts"
        },
        "serviceWorker": "apps/mobarmegeen/mobarmegeen-ui/ngsw-config.json",
        "define": {}
      },
      "configurations": {
        "production": {
          "budgets": [
            {
              "type": "initial",
              "maximumWarning": "500kb",
              "maximumError": "2mb"
            },
            {
              "type": "anyComponentStyle",
              "maximumWarning": "2kb"
            }
          ],
          "outputHashing": "all",
          "namedChunks": true
        },
        "development": {
          "optimization": false,
          "extractLicenses": false,
          "sourceMap": true
        }
      },
      "defaultConfiguration": "production"
    },
    "serve": {
      "executor": "@angular-devkit/build-angular:dev-server",
      "configurations": {
        "production": {
          "buildTarget": "mobarmegeen-ui:build:production"
        },
        "development": {
          "buildTarget": "mobarmegeen-ui:build:development"
        }
      },
      "defaultConfiguration": "development"
    },
    "extract-i18n": {
      "executor": "@angular-devkit/build-angular:extract-i18n",
      "options": {
        "buildTarget": "mobarmegeen-ui:build"
      }
    },
    "test": {
      "executor": "@angular-devkit/build-angular:karma",
      "options": {
        "polyfills": ["zone.js", "zone.js/testing"],
        "tsConfig": "tsconfig.spec.json",
        "inlineStyleLanguage": "scss",
        "assets": [
          "apps/mobarmegeen/mobarmegeen-ui/src/favicon.ico",
          "apps/mobarmegeen/mobarmegeen-ui/src/assets",
          "apps/mobarmegeen/mobarmegeen-ui/src/manifest.webmanifest",
          "apps/mobarmegeen/mobarmegeen-ui/src/scripts.mjs",
          "apps/mobarmegeen/mobarmegeen-ui/src/configs"
        ],
        "styles": [
          "apps/mobarmegeen/mobarmegeen-ui/src/styles.scss",
          "@angular/material/prebuilt-themes/indigo-pink.css"
        ],
        "scripts": []
      }
    }
  }
}

nx.json
{
  "$schema": "./node_modules/nx/schemas/nx-schema.json",
  "defaultBase": "main",
  "plugins": [
    {
      "plugin": "@nx/eslint/plugin",
      "options": {
        "targetName": "lint"
      }
    }
  ],
  "namedInputs": {
    "all": ["{projectRoot}/**/*", "sharedGlobals"],
    "src": ["{projectRoot}/src/**/*"],
    "sharedGlobals": []
  },
  "targetDefaults": {
    "build": {
      "cache": true,
      "dependsOn": ["^build"],
      "inputs": ["src"],
      "outputs": ["{projectRoot}/dist"]
    },
    "@angular-devkit/build-angular:application": {
      "cache": true,
      "dependsOn": ["^build"],
      "inputs": ["src", "^src"]
    }
  }
}

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.

Expected Behavior

zone.js should be resolved from the location of project.json, i.e. from workspace's node_modules rather than the top-level's root dir

GitHub Repo

No response

Steps to Reproduce

.

Nx Report

Node   : 20.10.0
OS     : linux-x64
pnpm   : 8.15.7

nx (global)  : 18.2.4
nx           : 18.2.4
@nx/jest     : 18.2.4
@nx/eslint   : 18.2.4
---------------------------------------
Registered Plugins:
@nx/eslint/plugin

Failure Logs

No response

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

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   
@AgentEnder AgentEnder added the scope: angular Issues related to Angular support in Nx label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: angular Issues related to Angular support in Nx type: bug
Projects
None yet
Development

No branches or pull requests

3 participants