Repository navigation
Closed
Description
🐞 bug report:
Affected Rule
The issue is caused by the rule: No specific rule, WORKSPACE setupIs this a regression?
NoDescription
A clear and concise description of the problem...The combination of the rules_node quickstart and the typescript install instructions does not result in a working setup.
🔬 Minimal Reproduction
After following rules_node quickstart guide, everything works as advertised. Once adding typescript into the mix, things start to go wrong.
After the install instructions, I end up with:
package.json
{
"name": "bazel-demo",
"license": "MIT",
"scripts": {
"build": "bazel build //...",
"test": "ibazel test //..."
},
"devDependencies": {
"@bazel/bazel": "^0.24.0",
"@bazel/buildifier": "^0.22.0",
"@bazel/ibazel": "^0.10.0",
"@bazel/typescript": "^0.27.9"
}
}WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "213dcf7e72f3acd4d1e369b7a356f3e5d9560f380bd655b13b7c0ea425d7c419",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.27.9/rules_nodejs-0.27.9.tar.gz"],
)
load("@build_bazel_rules_nodejs//:defs.bzl", "yarn_install")
yarn_install(
name = "npm",
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)
load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")
install_bazel_dependencies()
# Setup TypeScript toolchain
load("@npm_bazel_typescript//:index.bzl", "ts_setup_workspace")
ts_setup_workspace()BUILD.bazel
exports_files(["tsconfig.json"], visibility = ["//visibility:public"])Running $ yarn build outputs:
$ yarn build
yarn run v1.13.0
$ bazel build //...
ERROR: error loading package '': Encountered error while reading extension file 'install_bazel_dependencies.bzl': no such package '@npm//': Traceback (most recent call last):
File "/private/var/tmp/_bazel_fstephany/2568291785a61e5fb8e927e31fac1df5/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 287
_create_build_file(repository_ctx, node, repository_ctx...)
File "/private/var/tmp/_bazel_fstephany/2568291785a61e5fb8e927e31fac1df5/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 90, in _create_build_file
fail(("node failed: \nSTDOUT:\n%s\nST...)))
node failed:
STDOUT:
STDERR:
Could not find peer dependency 'typescript' of 'tsutils'
ERROR: error loading package '': Encountered error while reading extension file 'install_bazel_dependencies.bzl': no such package '@npm//': Traceback (most recent call last):
File "/private/var/tmp/_bazel_fstephany/2568291785a61e5fb8e927e31fac1df5/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 287
_create_build_file(repository_ctx, node, repository_ctx...)
File "/private/var/tmp/_bazel_fstephany/2568291785a61e5fb8e927e31fac1df5/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 90, in _create_build_file
fail(("node failed: \nSTDOUT:\n%s\nST...)))
node failed:
STDOUT:
STDERR:
Could not find peer dependency 'typescript' of 'tsutils'
INFO: Elapsed time: 1.890s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I guess this means that I should add typescript to package.json so I ran $ yarn add -D typescript
Then the error evolves to:
$ yarn build
yarn run v1.13.0
$ bazel build //...
ERROR: /Users/fstephany/Code/Play/ts-bazel/node_modules/@bazel/typescript/BUILD.bazel:57:1: no such package 'devserver': BUILD file not found on package path and referenced by '//node_modules/@bazel/typescript:npm_package'
ERROR: Analysis of target '//node_modules/@bazel/typescript:npm_package' failed; build aborted: no such package 'devserver': BUILD file not found on package path
INFO: Elapsed time: 5.413s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (10 packages loaded, 36 targets configured)
Fetching @build_bazel_rules_typescript_protobufs_compiletime_deps; Restarting.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Poking in the install notes from the typescript rules I added
load("@npm_bazel_typescript//:index.bzl", "ts_devserver", "ts_library")
at the end of my WORKSPACE. Then the error message changes:
$ yarn build
yarn run v1.13.0
$ bazel build //...
ERROR: /Users/fstephany/Code/Play/ts-bazel/node_modules/@bazel/typescript/BUILD.bazel:47:1: no such package 'docs': BUILD file not found on package path and referenced by '//node_modules/@bazel/typescript:generate_README'
ERROR: /Users/fstephany/Code/Play/ts-bazel/node_modules/@bazel/typescript/BUILD.bazel:47:1: no such package 'docs': BUILD file not found on package path and referenced by '//node_modules/@bazel/typescript:generate_README'
ERROR: Analysis of target '//node_modules/@bazel/typescript:generate_README' failed; build aborted: no such package 'docs': BUILD file not found on package path
INFO: Elapsed time: 0.170s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
My final directory structure:
$ tree -L 1 .
.
├── BUILD.bazel
├── README.md
├── WORKSPACE
├── bazel-bin -> /private/var/tmp/_bazel_fstephany/2568291785a61e5fb8e927e31fac1df5/execroot/__main__/bazel-out/darwin-fastbuild/bin
├── bazel-genfiles -> /private/var/tmp/_bazel_fstephany/2568291785a61e5fb8e927e31fac1df5/execroot/__main__/bazel-out/darwin-fastbuild/genfiles
├── bazel-out -> /private/var/tmp/_bazel_fstephany/2568291785a61e5fb8e927e31fac1df5/execroot/__main__/bazel-out
├── bazel-testlogs -> /private/var/tmp/_bazel_fstephany/2568291785a61e5fb8e927e31fac1df5/execroot/__main__/bazel-out/darwin-fastbuild/testlogs
├── bazel-ts-bazel -> /private/var/tmp/_bazel_fstephany/2568291785a61e5fb8e927e31fac1df5/execroot/__main__
├── node_modules
├── package.json
├── tsconfig.json
├── yarn-error.log
└── yarn.lock
6 directories, 7 files
🌍 Your Environment
Operating System:
macOS 10.14.3
Output of bazel version:
$ bazel version
Build label: 0.24.0
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Mar 26 16:15:16 2019 (1553616916)
Build timestamp: 1553616916
Build timestamp as int: 1553616916
Rules version (SHA):
213dcf7e72f3acd4d1e369b7a356f3e5d9560f380bd655b13b7c0ea425d7c419
Probably a rookie mistake but I can't get it :-/
Metadata
Metadata
Assignees
Labels
No labels
Activity
alexeagle commentedon Apr 3, 2019
Ah, the clue in your errors is
//node_modules/...- this means that Bazel is finding configurations in your localnode_modulesfolder. We don't intend that - since the quickstart uses the approach where Bazel manages its own copy of the node_modules tree. The missing instruction isecho node_modules > .bazelignoreSince you ran across it first: not having
typescriptinstalled ought to be caught by apeerDependencyfrom@bazel/typescripttotypescript. That said, installing your originalpackage.jsondoes printwhich is the idiomatic way for npm/yarn to tell you something won't work. But the TS instructions should say to install typescript too
Will fix the instructions, thanks for the clear report.
Clarify install instructions to fix a pitfall
fstephany commentedon Apr 3, 2019
That was it, thanks a lot @alexeagle :)
Indeed. And the README seems to make a good job at explaining the different possible options. Thanks!
Clarify install instructions to fix a pitfall (#648)
Initial Toolchain Support