Skip to content

Failed to load the resty.core module when using include with js_import in http-snippet #13135

Closed
@thisissoamazin

Description

@thisissoamazin

Adding module to the base image

I'm customizing the ingress-nginx controller by using a modified nginx-base image. Specifically, I want to add the NJS module to enable advanced CORS handling logic via js_import and js_header_filter directives.

I build my own nginx-base image based on registry.k8s.io/ingress-nginx/nginx:v1.2.1, only added the NJS module.

Source

Built from the helm-chart-4.12.1 branch

The issue

When I use the custom base image and enable my custom CORS logic via http-snippet in the HelmRelease config:

controller:
  config:
    http-snippet: |
      include /etc/nginx/CORS_http.conf;
cat /etc/nginx/CORS_http.conf
js_var $cors_config_file; # set or override in server or location contexts of nginx configuration to point to configuration file
js_var $cors_is_valid_preflight_request; # set by cors.header_filter to signal detection of a valid pre-flight request
js_import cors from /etc/nginx/njs/http/cors.js;

I get the following error:
failed to load the 'resty.core' module

2025/03/31 09:41:20 [alert] 18#18: failed to load the 'resty.core' module (https://github.com/openresty/lua-resty-core); ensure you are using an OpenResty release from https://openresty.org/en/download.html (reason: module 'resty.core' not found:
 no field package.preload['resty.core']
 no file '/etc/nginx/lua/resty/core.lua'
 no file '../lua-resty-core/lib/resty/core.lua'
 no file '../lua-resty-lrucache/lib/resty/core.lua'
 no file './resty/core.lua'
 no file '/usr/local/share/luajit-2.1/resty/core.lua'
 no file '/usr/local/share/lua/5.1/resty/core.lua'
 no file '/usr/local/share/lua/5.1/resty/core/init.lua'

Which seems unrelated to my CORS config or NJS module.

Why this is weird

This error disappears when I comment out the http-snippet. But the snippet itself only references js_import (NJS), and does not use Lua at all.

It seems like enabling NJS somehow triggers Lua module loading even when Lua isn't used.

What I want to know

  1. Is this behavior expected?

  2. Why does including an http-snippet that only uses js_import (NJS) cause the controller to try loading resty.core?

  3. Is there a config option to disable Lua entirely and avoid this error?

Also tried building from main, from branches starting with controller v1.12.0 down to v1.10.0, and from helm-chart-4.12.1 down to helm-chart-4.10.0 - same result every time.
Tried both building manually and using the current ci.yaml from a fork of the ingress-nginx repo.

Thanks in advance.

cc @rikatz @strongjz

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/supportCategorizes issue or PR as a support question.needs-priorityneeds-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions