Getting: unknown directive "js_import" when njs used with Nginx
Asked Answered
P

2

6

I am making the following statement in the Nginx conf:

js_import http.js;

But it seems to give me unknown directive "js_import"

I have verified whether the njs is installed. I can seem to get into the cli. Version of njs is 0.3.9

The below statement seems to be working and is placehttp block:

js_include http.js

This also seem to work and is placed in the server block inside http block:

js_content hello

Nginx seems to be the latest version.

I cannot seems to find what I am missing here.

Any help is greatly appreciated.

Prolongation answered 28/5, 2020 at 9:20 Comment(3)
Where have you placed the js_import statement? It is only permitted within the http or stream blocks.Simulated
I am placing in the http block.Prolongation
I have the same problem, I copied and pasted the example from the doc. The load_module directive is there and the module file is present... (nginx 1.17.5 from docker)Tranche
A
5

reading this and putting

load_module /usr/lib/nginx/modules/ngx_http_js_module.so;

at the top of my nginx.conf solved my problem you may need to put something like this

load_module modules/ngx_http_js_module.so;

Angio answered 1/6, 2020 at 7:0 Comment(2)
Thanks for your comment. I have already mentioned the load_module modules/ngx_http_js_module.so; at the top. It is still not working. I have edited the question please check.Prolongation
Yes I did. I tried with non existent paths to verify the same.Prolongation
B
0

Verify that you are using the latest nginx version or ngx_http_js_module version js_import come with ngx_http_js_module v0.4.0 as stated in the documenttion http://nginx.org/en/docs/http/ngx_http_js_module.html#js_import

Brannan answered 23/6, 2020 at 12:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.