bazel-contrib / bazel-contrib/rules_nodejs

[Bug]: `@bazel/runfiles` should not throw an exception if used outside of a Bazel invocation

Open
#3,770 0 comments 0 reactions 0 assignees View on GitHub
bug enhancement need: funding
Dominant language
Starlark
Stars
762
Forks
531
Avg merge
10h 31m
Merged PRs (30d)
3

Description

### What happened?

I have a library that sometimes expects to be used in a Bazel build, but can also be used in a regular JS project built using `npm`. One utility function attempts to locate files, using `@bazel/runfiles` if it can't find the files the regular way.

When used in the regular `npm` project, the line `const { runfiles } = require('@bazel/runfiles')` throws an exception. I would expect the check to be done when the `resolve` function is called, allowing `@bazel/runfiles` to be used as a regular library in a normal JS project.

### Version

Bazel 7.2.1.
Runfiles 5.8.1

### How to reproduce

```shell
Load `const { runfiles } = require('@bazel/runfiles')` in a regular project
```

### Any other information?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.