bazel-contrib / rules_nodejs

NodeJS toolchain for Bazel.
https://bazelbuild.github.io/rules_nodejs/
Apache License 2.0
733 stars 522 forks source link

Build error while building angular project with Bazel - Workspace configuration file (angular.json, .angular.json, workspace.json, .workspace.json) cannot be found #2292

Closed amitkatyal closed 3 years ago

amitkatyal commented 4 years ago

🐞 bug report

Affected Rule

Is this a regression?

Not a regression..

Description

Hi,

I am new to Angular & Bazel and trying to build angular project with Bazel.

I'm able to build the stand alone angular project with Bazel architect-cli approach by following rules_nodejs/example/architect_cli example.

However, when I am trying to integrate angular build with existing "go lang" build system, I am getting below error

_Workspace configuration file (angular.json, .angular.json, workspace.json, .workspace.json) cannot be found in '/private/var/tmp/_bazelamit.katyal/c43f5fa55236092ecfb8340b31fd2a36/sandbox/darwin-sandbox/679/execroot/XXX' or in parent directories.

The problem is that architect-cli build tool is looking for angular.json file under current working directory. But bazel is inside sand-box directory root path which doesn't have angular.json file.

As mentioned, it works fine if WORKSPACE and BUILD.BAZEL are under angular folder. But my requirement is to bring the bring angular dependencies under global (existing) workspace file.

Is there a workaround to address this issue ?

Please provide me some pointers to resolve this issue.

πŸ”¬ Minimal Reproduction

πŸ”₯ Exception or Error

_Workspace configuration file (angular.json, .angular.json, workspace.json, .workspace.json) cannot be found in '/private/var/tmp/_bazelamit.katyal/c43f5fa55236092ecfb8340b31fd2a36/sandbox/darwin-sandbox/679/execroot/XXX' or in parent directories.

🌍 Your Environment

Operating System:

MAC OS

Output of bazel version:

IN-GN-52351:gateway amit.katyal$ bazel version Build label: 3.4.1 Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar Build time: Tue Jul 14 06:32:14 2020 (1594708334) Build timestamp: 1594708334 Build timestamp as int: 1594708334

Rules_nodejs version:

Fetch rules_nodejs so we can install our npm dependencies

http_archive( name = "build_bazel_rules_nodejs", sha256 = "0f2de53628e848c1691e5729b515022f5a77369c76a09fbe55611e12731c90e3", urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/2.0.1/rules_nodejs-2.0.1.tar.gz"], )

Check the bazel version and download npm dependencies

load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install")

Setup the Node.js toolchain & install our npm dependencies into @npm

yarn_install(

Name this npm so that Bazel Label references look like @npm//package

name = "npm",
package_json = "//ui/angular/portal:package.json",
# Turn off symlink_node_modules here as it causes extreme flakiness on buildkite
# macos CI with missing files in node_modules.
# TODO: track down the root cause of the flakiness; it may be something to
# do with how the Bazel team has setup their macos virtualization.
symlink_node_modules = False,
yarn_lock = "//ui/angular/portal:yarn.lock",

)

package.json { "name": "portal", "version": "0.0.0", "scripts": { "ng": "ng", "start": "bazel run :serve", "build": "bazel build :build", "test": "bazel test :test", "lint": "bazel run :lint", "e2e": "bazel test :e2e", "bundle-styles": "scss-bundle -p scss-bundle.config.json", "checkCopyright": "node tasks/check-copyright.js", "checkCopyright:cleanup": "BUILD_MODE=cleanup node tasks/check-copyright.js", "checkI18n": "node tasks/check-i18n.js", "i18n": "cp ./projects/wifi/src/assets/i18n/en-us.json ./dist/wifi", "package": "npm run checkCopyright && npm run checkI18n && ng build wifi && npm run bundle-styles && npm run i18n && cd dist/wifi && npm pack" }, "private": true, "dependencies": { "@angular-devkit/architect-cli": "0.7.2", "@angular/animations": "~7.2.0", "@angular/cdk": "^7.3.7", "@angular/common": "~7.2.0", "@angular/compiler": "~7.2.0", "@angular/core": "~7.2.0", "@angular/forms": "~7.2.0", "@angular/platform-browser": "~7.2.0", "@angular/platform-browser-dynamic": "~7.2.0", "@angular/router": "~7.2.0", "@ngx-translate/core": "^11.0.1", "@ngx-translate/http-loader": "^4.0.0", "@sophos/core": "0.101.0", "angular2-toaster": "^7.0.0", "bootstrap": "^4.5.0", "chart.js": "^2.9.3", "core-js": "^2.5.4", "font-awesome": "4.7.0", "jquery": "^3.2.1", "lodash-es": "^4.17.4", "ngx-bootstrap": "^3.1.4", "ngx-cookie-service": "^2.2.0", "primeflex": "^1.0.0", "primeicons": "^2.0.0", "primeng": "^7.1.3", "rxjs": "~6.3.3", "tslib": "^1.9.0", "zone.js": "~0.8.26" }, "devDependencies": { "@angular-devkit/build-angular": "~0.13.0", "@angular-devkit/build-ng-packagr": "~0.13.0", "@angular/cli": "~7.3.7", "@angular/compiler-cli": "~7.2.0", "@angular/language-service": "~7.2.0", "@babel/cli": "^7.6.0", "@babel/core": "^7.6.0", "@babel/preset-env": "^7.6.0", "@bazel/angular": "^2.0.0", "@bazel/bazelisk": "^1.5.0", "@bazel/benchmark-runner": "^0.1.0", "@bazel/buildifier": "^3.4.0", "@bazel/ibazel": "^0.13.1", "@bazel/karma": "^2.0.0", "@bazel/protractor": "^2.0.0", "@bazel/rollup": "^2.0.0", "@bazel/terser": "^2.0.0", "@bazel/typescript": "^2.0.0", "@types/jasmine": "~2.8.8", "@types/jasminewd2": "~2.0.3", "@types/node": "~8.9.4", "codelyzer": "~4.5.0", "jasmine-core": "~2.99.1", "jasmine-spec-reporter": "~4.2.1", "karma": "~4.0.0", "karma-chrome-launcher": "~2.2.0", "karma-coverage-istanbul-reporter": "~2.0.1", "karma-jasmine": "~1.1.2", "karma-jasmine-html-reporter": "^0.2.2", "karma-junit-reporter": "^1.2.0", "ng-packagr": "^4.2.0", "protractor": "~5.4.0", "scss-bundle": "3.0.2", "ts-node": "~7.0.0", "tsickle": ">=0.34.0", "tslib": "^1.9.0", "tslint": "~5.11.0", "typescript": "~3.2.2" } }

Anything else relevant?

amitkatyal commented 3 years ago

fixed

cschuet commented 3 years ago

@amitkatyal I am running into the same problem. How did you end up solving it?

amitkatyal commented 3 years ago

@cschuet, I had fixed it by not compiling using architect CLI and referred to https://github.com/angular/angular-bazel-example.

cschuet commented 3 years ago

Thanks for getting back. I found a solution where I locate the angular.json in the root of the monorepo, which is ok since it is a map from project name to Angular project specific settings and have all other files e.g. tsconfig.json in the project folders.