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

build file inside of package prevents dependency installation #408

Closed
vmax opened this issue Nov 7, 2018 · 7 comments
Closed

build file inside of package prevents dependency installation #408

vmax opened this issue Nov 7, 2018 · 7 comments
Assignees
Labels

Comments

@vmax
Copy link

vmax commented Nov 7, 2018

While migrating electron project to be built by bazel and use rules_nodejs (any link to successful migration will be appreciated!), I encountered an issue, which is reproducible with this simple example:

WORKSPACE:

git_repository(
    name = "build_bazel_rules_nodejs",
    remote = "https://github.com/bazelbuild/rules_nodejs.git",
    commit = "173d858483b3dbbc0d7c8a05eb4a0f0e1285f0b3",
)

load("@build_bazel_rules_nodejs//:package.bzl", "rules_nodejs_dependencies")
rules_nodejs_dependencies()

load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories")
node_repositories(
	package_json = ["//:package.json"]
)

load("@build_bazel_rules_nodejs//:defs.bzl", "npm_install")
npm_install(
    name = "npm",
    package_json = "//:package.json",
    package_lock_json = "//:package-lock.json",
)

package.json:

{
	"dependencies": {
		"humanize-plus": "^1.8.2"
	}
}

package-lock.json can be generated by npm i, BUILD file is empty

Then, running bazel query @npm//... results in an error:

RROR: /private/var/tmp/_bazel_vmax/b34e8677dff10fd1251bb3d7a93c6664/external/npm/node_modules/humanize-plus/bin/BUILD:9:1: invalid character: '$'
ERROR: /private/var/tmp/_bazel_vmax/b34e8677dff10fd1251bb3d7a93c6664/external/npm/node_modules/humanize-plus/bin/BUILD:9:3: invalid character: '$'
ERROR: /private/var/tmp/_bazel_vmax/b34e8677dff10fd1251bb3d7a93c6664/external/npm/node_modules/humanize-plus/bin/BUILD:9:14: invalid character: '&'
ERROR: /private/var/tmp/_bazel_vmax/b34e8677dff10fd1251bb3d7a93c6664/external/npm/node_modules/humanize-plus/bin/BUILD:9:16: syntax error at '/': expected expression

ERROR: /private/var/tmp/_bazel_vmax/b34e8677dff10fd1251bb3d7a93c6664/external/npm/node_modules/humanize-plus/bin/BUILD:10:7: invalid character: '$'
ERROR: /private/var/tmp/_bazel_vmax/b34e8677dff10fd1251bb3d7a93c6664/external/npm/node_modules/humanize-plus/bin/BUILD:10:8: invalid character: '?'
ERROR: /private/var/tmp/_bazel_vmax/b34e8677dff10fd1251bb3d7a93c6664/external/npm/node_modules/humanize-plus/bin/BUILD:10:14: syntax error at '0': expected ',', 'for' or ']'
ERROR: /private/var/tmp/_bazel_vmax/b34e8677dff10fd1251bb3d7a93c6664/external/npm/node_modules/humanize-plus/bin/BUILD:11:4: indentation error
ERROR: /private/var/tmp/_bazel_vmax/b34e8677dff10fd1251bb3d7a93c6664/external/npm/node_modules/humanize-plus/bin/BUILD:11:18: invalid character: '$'
ERROR: /private/var/tmp/_bazel_vmax/b34e8677dff10fd1251bb3d7a93c6664/external/npm/node_modules/humanize-plus/bin/BUILD:11:20: invalid character: '$'
ERROR: /private/var/tmp/_bazel_vmax/b34e8677dff10fd1251bb3d7a93c6664/external/npm/node_modules/humanize-plus/bin/BUILD:12:8: invalid character: '$'
ERROR: /private/var/tmp/_bazel_vmax/b34e8677dff10fd1251bb3d7a93c6664/external/npm/node_modules/humanize-plus/bin/BUILD:12:9: syntax error at 'PROJECT_ROOT': expected newline
ERROR: /private/var/tmp/_bazel_vmax/b34e8677dff10fd1251bb3d7a93c6664/external/npm/node_modules/humanize-plus/bin/BUILD:12:21: syntax error at 'outdent': expected expression
ERROR: /private/var/tmp/_bazel_vmax/b34e8677dff10fd1251bb3d7a93c6664/external/npm/node_modules/humanize-plus/bin/BUILD:10:1: if statements are not allowed in BUILD files. You may move conditional logic to a function definition (in a .bzl file), or for simple cases use an if expression.
ERROR: /private/var/tmp/_bazel_vmax/b34e8677dff10fd1251bb3d7a93c6664/external/npm/node_modules/humanize-plus/bin/BUILD:9:16: contains syntax error(s)
ERROR: /private/var/tmp/_bazel_vmax/b34e8677dff10fd1251bb3d7a93c6664/external/npm/node_modules/humanize-plus/bin/BUILD:10:5: contains syntax error(s)
ERROR: /private/var/tmp/_bazel_vmax/b34e8677dff10fd1251bb3d7a93c6664/external/npm/node_modules/humanize-plus/bin/BUILD:11:4: contains syntax error(s)
ERROR: /private/var/tmp/_bazel_vmax/b34e8677dff10fd1251bb3d7a93c6664/external/npm/node_modules/humanize-plus/bin/BUILD:12:5: name 'cd' is not defined
ERROR: /private/var/tmp/_bazel_vmax/b34e8677dff10fd1251bb3d7a93c6664/external/npm/node_modules/humanize-plus/bin/BUILD:12:21: contains syntax error(s)
ERROR: error loading package '@npm//node_modules/humanize-plus/bin': Package 'node_modules/humanize-plus/bin' contains errors

humanize-plus/bin/build can be seen here

@lolski
Copy link

lolski commented Nov 7, 2018

Are those BUILD files supposed to be Bazel BUILD files or just a regular file which happens to be called BUILD? I had a similar issue where I had to clean the node_modules folder before re-running Bazel.

@haikalpribadi
Copy link

That's exactly the issue @lolski - node_modules/ is something that is generated when building a node application. If that folder contains BUILD files (not from Bazel), then it gets in the way of our Bazel build execution.

@bugzpodder
Copy link

bugzpodder commented Nov 7, 2018

I think bazel has some ignore rules you can work with.

@haikalpribadi
Copy link

Where can we find documentation for this @bugzpodder ? Thank you!

@Toxicable
Copy link

.bazelignore would be the one yopu want

@bugzpodder
Copy link

Yep, https://docs.bazel.build/versions/master/guide.html#.bazelignore
there is also the deleted_packaged flag: bazelbuild/bazel#4888 (comment)

@alexeagle
Copy link
Collaborator

.bazelignore is meant to ignore files that appear in your own source tree.
our general approach is to delete BUILD and BUILD.bazel files we find in the node_modules so that Bazel doesn't try to act on them as it does here.
https://github.com/bazelbuild/rules_nodejs/blob/master/internal/npm_install/generate_build_file.js#L169-L172
I think the bug is that if the filesystem is case-insensitive then we also need to make that comparison case-insensitive.

@alexeagle alexeagle added the bug label Nov 19, 2018
alexeagle pushed a commit to alexeagle/rules_nodejs that referenced this issue Oct 17, 2020
Closes bazel-contrib#408

PiperOrigin-RevId: 233109259
alexeagle pushed a commit to alexeagle/rules_nodejs that referenced this issue Oct 18, 2020
Closes bazel-contrib#408

PiperOrigin-RevId: 233109259
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants