bazel-contrib / rules_nodejs

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

Examples provided do not work out of the box (config files missing) #2359

Closed tomasdev closed 3 years ago

tomasdev commented 3 years ago

πŸ”¬ Minimal Reproduction

Run the following:

git clone git@github.com:bazelbuild/rules_nodejs.git
cd rules_nodejs/examples/app
npm install
npm install --save-dev @bazel/bazel # only required if you don't have bazel globally
npx bazel build :prodserver # or `bazel build :prodserver` if you have it globally

πŸ”₯ Exception or Error


ERROR: /Users/tomas/WORK/rules_nodejs/examples/app/BUILD.bazel:22:1: every rule of type rollup_bundle implicitly depends upon the target '@npm//@bazel/rollup:rollup.config.js', but this target could not be found because of: no such target '@npm//@bazel/rollup:rollup.config.js': target 'rollup.config.js' not declared in package '@bazel/rollup'; however, a source file of this name exists.  (Perhaps add 'exports_files(["rollup.config.js"])' to @bazel/rollup/BUILD?) defined by /private/var/tmp/_bazel_tomas/9cd5c7a033e236bbd0e2adab9e32ef7a/external/npm/@bazel/rollup/BUILD.bazel
Documentation for implicit attribute config_file of rules of type rollup_bundle:
A `rollup.config.js` file

Passed to the `--config` option, see [the config doc](https://rollupjs.org/guide/en/#configuration-files)

If not set, a default basic Rollup config is used.
ERROR: /Users/tomas/WORK/rules_nodejs/examples/app/BUILD.bazel:28:1: every rule of type terser_minified implicitly depends upon the target '@npm//@bazel/terser:terser_config.default.json', but this target could not be found because of: no such target '@npm//@bazel/terser:terser_config.default.json': target 'terser_config.default.json' not declared in package '@bazel/terser'; however, a source file of this name exists.  (Perhaps add 'exports_files(["terser_config.default.json"])' to @bazel/terser/BUILD?) defined by /private/var/tmp/_bazel_tomas/9cd5c7a033e236bbd0e2adab9e32ef7a/external/npm/@bazel/terser/BUILD.bazel
Documentation for implicit attribute config_file of rules of type terser_minified:
A JSON file containing Terser minify() options.

This is the file you would pass to the --config-file argument in terser's CLI.
https://github.com/terser-js/terser#minify-options documents the content of the file.

Bazel will make a copy of your config file, treating it as a template.

Run bazel with `--subcommands` to see the path to the copied file.

If you use the magic strings `"bazel_debug"` or `"bazel_no_debug"`, these will be
replaced with `true` and `false` respecting the value of the `debug` attribute
or the `--compilation_mode=dbg` bazel flag.

For example

```
{
    "compress": {
        "arrows": "bazel_no_debug"
    }
}
```

Will disable the `arrows` compression setting when debugging.

If `config_file` isn't supplied, Bazel will use a default config file.
ERROR: Analysis of target '//:prodserver' failed; build aborted: Analysis failed

🌍 Your Environment

Operating System:

  
Mac OS X Big Sur 11.0.1 (20B29)
  

Output of bazel version:

  
Build label: 2.1.0
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Feb 7 13:04:00 2020 (1581080640)
Build timestamp: 1581080640
Build timestamp as int: 1581080640
  

Rules_nodejs version:

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

Anything else relevant?

Am I doing something wrong perhaps?

tomasdev commented 3 years ago

Perhaps related to https://github.com/bazelbuild/bazel/issues/2835 ?

tomasdev commented 3 years ago

May have been introduced by https://github.com/bazelbuild/rules_nodejs/pull/2193 ?

tomasdev commented 3 years ago

Trying out v3.0.0 rc-1 throws

ERROR: error loading package '': in /private/var/tmp/_bazel_tomas/3532d3aa619a717cd847371d067034d5/external/npm/@bazel/concatjs/index.bzl: in /private/var/tmp/_bazel_tomas/3532d3aa619a717cd847371d067034d5/external/npm/@bazel/concatjs/web_test/karma_web_test.bzl: Unable to find package for @io_bazel_rules_webtesting//web:web.bzl: The repository '@io_bazel_rules_webtesting' could not be resolved.

Edit: The error above is fixed by adding to WORKSPACE:

http_archive(
    name = "io_bazel_rules_webtesting",
    sha256 = "9bb461d5ef08e850025480bab185fd269242d4e533bca75bfb748001ceb343c3",
    urls = ["https://github.com/bazelbuild/rules_webtesting/releases/download/0.3.3/rules_webtesting.tar.gz"],
)

But then that gets you this error:

ERROR: error loading package '': in /private/var/tmp/_bazel_tomas/3532d3aa619a717cd847371d067034d5/external/npm/@bazel/concatjs/index.bzl: in /private/var/tmp/_bazel_tomas/3532d3aa619a717cd847371d067034d5/external/npm/@bazel/concatjs/web_test/karma_web_test.bzl: in /private/var/tmp/_bazel_tomas/3532d3aa619a717cd847371d067034d5/external/io_bazel_rules_webtesting/web/web.bzl: in /private/var/tmp/_bazel_tomas/3532d3aa619a717cd847371d067034d5/external/io_bazel_rules_webtesting/web/internal/custom_browser.bzl: Unable to find package for @bazel_skylib//lib:dicts.bzl: The repository '@bazel_skylib' could not be resolved.

Edit 2: which was fixed by also adding to WORKSPACE:

load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories")
web_test_repositories()

Then tsconfig blew up and had to add the following to my main BUILD.bazel

exports_files(
  ["tsconfig.json"],
  visibility = ["//visibility:public"],
)
tomasdev commented 3 years ago

The issue does simply not happen on v3.0.0-rc.1, so closing.

I was able to run the example with these:

git clone git@github.com:bazelbuild/rules_nodejs.git
git checkout 3.x
yarn add -D @bazel/bazelisk @bazel/ibazel                         
node_modules/@bazel/ibazel/bin/darwin_amd64/ibazel run :prodserver # didnt find a better way to execute the local ibazel lol but it works!