1

I am trying to setup for the first time bazel with rules_nodejs on the dummy project. The project structure is organised as follows:

enter image description here

The folder app1 contains NODE application and the folder app2 will be a GO based application.

The index.js is a very simple application:

const _ = require("lodash");

const numbers = [1, 5, 8, 10, 1, 5, 15, 42, 5];
const uniqNumbers = _.uniq(numbers);
console.log(uniqNumbers);

Running the application with the command:

bazel run //app1

it shows the error message:

ERROR: An error occurred during the fetch of repository 'app1':
   Traceback (most recent call last):
        File "/private/var/tmp/_bazel_developer/de6f8818d27e2451d76ec34773e78a6e/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 965, column 13, in _yarn_install_impl
                fail("yarn_install failed: %s (%s)" % (result.stdout, result.stderr))
Error in fail: yarn_install failed: yarn install v1.22.11
[1/4] Resolving packages...
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
 (error Couldn't find any versions for "lodash" that matches "ˆ4.17.21"
)
ERROR: /Users/developer/node/bazel_play/WORKSPACE.bazel:22:13: fetching yarn_install rule //external:app1: Traceback (most recent call last):
        File "/private/var/tmp/_bazel_developer/de6f8818d27e2451d76ec34773e78a6e/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 965, column 13, in _yarn_install_impl
                fail("yarn_install failed: %s (%s)" % (result.stdout, result.stderr))
Error in fail: yarn_install failed: yarn install v1.22.11
[1/4] Resolving packages...
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
 (error Couldn't find any versions for "lodash" that matches "ˆ4.17.21"
)
ERROR: /Users/developer/node/bazel_play/app1/BUILD.bazel:3:14: //app1:app1 depends on @app1//lodash:lodash in repository @app1 which failed to fetch. no such package '@app1//lodash': yarn_install failed: yarn install v1.22.11
[1/4] Resolving packages...
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
 (error Couldn't find any versions for "lodash" that matches "ˆ4.17.21"
)
ERROR: Analysis of target '//app1:app1' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.591s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded, 0 targets configured)
FAILED: Build did NOT complete successfully (1 packages loaded, 0 targets configured)

I assume the problem is the lodash module is missing. How can I do yarn install with bazel command?
All source files can be found here: https://github.com/softshipper/bazel_play

And also could anyone please explain the purpose of yarn_install rule?

softshipper
  • 32,463
  • 51
  • 192
  • 400
  • You need to install in lodash in softshipper/bazel_play folder first. And refer this https://stackoverflow.com/questions/27431187/cannot-find-module-lodash for more. Then you can build your repo with bazel. $ npm install lodash --save – SG_Bazel Jun 20 '22 at 09:16

0 Answers0