rajkris
rajkris

Reputation: 1793

Getting: unknown directive "js_import" when njs used with Nginx

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.

Upvotes: 7

Views: 8981

Answers (3)

Goaul
Goaul

Reputation: 1560

Had same issue in dockerized system with slightly different nginx config files. Project uses 3 dockers, where 2 dockers worked without problems, but third was not running and had this error:

unknown directive "js_import"

Initial running nginx-1.26.2 and then updated to nginx-1.27.3 while using njs-0.8.5, that did not help.

Solution was to update njs to njs-0.8.9.

Upvotes: 0

Ministicraft
Ministicraft

Reputation: 1

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

Upvotes: 0

raoof
raoof

Reputation: 572

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;

Upvotes: 5

Related Questions