I have a Bazel BUILD file with a nodejs_image
:
package(default_visibility = ["//visibility:public"])
load("@npm_bazel_typescript//:index.bzl", "ts_library")
ts_library(
name = "lib",
srcs = glob(
include = ["**/*.ts"],
exclude = ["**/*.spec.ts"]
),
deps = [
"//packages/enums/src:lib",
"//packages/hello/src:lib",
"@npm//faker",
"@npm//@types/faker",
"@npm//express",
"@npm//@types/express",
"@npm//cors",
],
)
load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")
nodejs_image(
name = "server",
data = [":lib"],
entry_point = ":index.ts",
)
which boots up a simple Express Node.Js server:
app.listen(3000, () => console.log('listening on port 3000'));
When I run
ibazel run //services/server/src:server
the server starts just fine. But when I change some code and the Bazel Watcher restarts, I get this error:
Error: listen EADDRINUSE: address already in use :::3000
Hence, the previous Node.Js process wasn't killed and the port is still in use.
Do I have to handle the termination inside my Node.Js application?
Or is there some other method to run Node.Js code with Bazel Watcher?
Or is it an issue with the Bazel Watcher?
You can try it yourself: https://github.com/flolude/minimal-bazel-monorepo/tree/f23b960b57a94abbb5cbc13853b3e8ec4a1997ab
As @Toxicable has stated, I've changed nodejs_image
to nodejs_binary
like this:
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
nodejs_binary(
name = "server",
data = [":lib"],
entry_point = ":index.ts",
)
Which fixed the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With