diff --git a/mainline/alpine-perl/Dockerfile b/mainline/alpine-perl/Dockerfile
index 1d46a0c59e832fec0718ea4ebd916341a1cdc2a6..d14ebc4b2759e8dc62db18fc9b5bd9c722dd2a1a 100644
--- a/mainline/alpine-perl/Dockerfile
+++ b/mainline/alpine-perl/Dockerfile
@@ -3,7 +3,7 @@ FROM alpine:3.11
 LABEL maintainer="NGINX Docker Maintainers <docker-maint@nginx.com>"
 
 ENV NGINX_VERSION 1.17.10
-ENV NJS_VERSION   0.3.9
+ENV NJS_VERSION   0.4.0
 ENV PKG_RELEASE   1
 
 RUN set -x \
diff --git a/mainline/alpine/Dockerfile b/mainline/alpine/Dockerfile
index 5d3bea962c63867f26ce68d65cdfbb8db5984b79..6b8391862916b83c57dc255def956c8b23aac01f 100644
--- a/mainline/alpine/Dockerfile
+++ b/mainline/alpine/Dockerfile
@@ -3,7 +3,7 @@ FROM alpine:3.11
 LABEL maintainer="NGINX Docker Maintainers <docker-maint@nginx.com>"
 
 ENV NGINX_VERSION 1.17.10
-ENV NJS_VERSION   0.3.9
+ENV NJS_VERSION   0.4.0
 ENV PKG_RELEASE   1
 
 RUN set -x \
diff --git a/mainline/buster-perl/Dockerfile b/mainline/buster-perl/Dockerfile
index eabb7223c3ea21abbcc5f0c3c0458a8e51746fbe..456baaa969b4f402f8bcadb522f8d6ad8e15ac99 100644
--- a/mainline/buster-perl/Dockerfile
+++ b/mainline/buster-perl/Dockerfile
@@ -3,7 +3,7 @@ FROM debian:buster-slim
 LABEL maintainer="NGINX Docker Maintainers <docker-maint@nginx.com>"
 
 ENV NGINX_VERSION   1.17.10
-ENV NJS_VERSION     0.3.9
+ENV NJS_VERSION     0.4.0
 ENV PKG_RELEASE     1~buster
 
 RUN set -x \
diff --git a/mainline/buster/Dockerfile b/mainline/buster/Dockerfile
index 4c2cc9a7a151ee11abb41cd97de33f324b44d366..da207926efcff275e6d3e5e9450790b9df6b42bc 100644
--- a/mainline/buster/Dockerfile
+++ b/mainline/buster/Dockerfile
@@ -3,7 +3,7 @@ FROM debian:buster-slim
 LABEL maintainer="NGINX Docker Maintainers <docker-maint@nginx.com>"
 
 ENV NGINX_VERSION   1.17.10
-ENV NJS_VERSION     0.3.9
+ENV NJS_VERSION     0.4.0
 ENV PKG_RELEASE     1~buster
 
 RUN set -x \
diff --git a/stable/alpine-perl/Dockerfile b/stable/alpine-perl/Dockerfile
index e094aca8933f1f0a07d3ff34bd999b0204dde59e..8aa45d0c3f05436cd36c4b16696eb601532caa51 100644
--- a/stable/alpine-perl/Dockerfile
+++ b/stable/alpine-perl/Dockerfile
@@ -3,7 +3,7 @@ FROM alpine:3.11
 LABEL maintainer="NGINX Docker Maintainers <docker-maint@nginx.com>"
 
 ENV NGINX_VERSION 1.18.0
-ENV NJS_VERSION   0.3.9
+ENV NJS_VERSION   0.4.0
 ENV PKG_RELEASE   1
 
 RUN set -x \
@@ -65,7 +65,7 @@ RUN set -x \
                 && cd ${tempDir} \
                 && hg clone https://hg.nginx.org/pkg-oss \
                 && cd pkg-oss \
-                && hg up ${NGINX_VERSION}-${PKG_RELEASE} \
+                && hg up -r 474 \
                 && cd alpine \
                 && make all \
                 && apk index -o ${tempDir}/packages/alpine/${apkArch}/APKINDEX.tar.gz ${tempDir}/packages/alpine/${apkArch}/*.apk \
diff --git a/stable/alpine/Dockerfile b/stable/alpine/Dockerfile
index 517fc6461de8eeb736ada56f328c62d4cc2f5873..fedb169cda20ae278aa3e7d6cb151042a908ea49 100644
--- a/stable/alpine/Dockerfile
+++ b/stable/alpine/Dockerfile
@@ -3,7 +3,7 @@ FROM alpine:3.11
 LABEL maintainer="NGINX Docker Maintainers <docker-maint@nginx.com>"
 
 ENV NGINX_VERSION 1.18.0
-ENV NJS_VERSION   0.3.9
+ENV NJS_VERSION   0.4.0
 ENV PKG_RELEASE   1
 
 RUN set -x \
@@ -64,7 +64,7 @@ RUN set -x \
                 && cd ${tempDir} \
                 && hg clone https://hg.nginx.org/pkg-oss \
                 && cd pkg-oss \
-                && hg up ${NGINX_VERSION}-${PKG_RELEASE} \
+                && hg up -r 474 \
                 && cd alpine \
                 && make all \
                 && apk index -o ${tempDir}/packages/alpine/${apkArch}/APKINDEX.tar.gz ${tempDir}/packages/alpine/${apkArch}/*.apk \
diff --git a/stable/buster-perl/Dockerfile b/stable/buster-perl/Dockerfile
index 890a455d1008ca46558a5128201faf0960dba821..f313a7bc4c1e5f0190f90b5aa35eab32873ba62c 100644
--- a/stable/buster-perl/Dockerfile
+++ b/stable/buster-perl/Dockerfile
@@ -3,7 +3,7 @@ FROM debian:buster-slim
 LABEL maintainer="NGINX Docker Maintainers <docker-maint@nginx.com>"
 
 ENV NGINX_VERSION   1.18.0
-ENV NJS_VERSION     0.3.9
+ENV NJS_VERSION     0.4.0
 ENV PKG_RELEASE     1~buster
 
 RUN set -x \
diff --git a/stable/buster/Dockerfile b/stable/buster/Dockerfile
index d14be0270563c2182a9b079226049cc112af46e0..22085bc511a2f4e450f7a3fc79d51e93d4a1ff01 100644
--- a/stable/buster/Dockerfile
+++ b/stable/buster/Dockerfile
@@ -3,7 +3,7 @@ FROM debian:buster-slim
 LABEL maintainer="NGINX Docker Maintainers <docker-maint@nginx.com>"
 
 ENV NGINX_VERSION   1.18.0
-ENV NJS_VERSION     0.3.9
+ENV NJS_VERSION     0.4.0
 ENV PKG_RELEASE     1~buster
 
 RUN set -x \