projectdiscovery/nuclei · error
ExportAs expects 2 arguments
Error message
ExportAs expects 2 arguments
What it means
A JavaScript (code protocol) template called the registered helper ExportAs with an argument count other than 2. The binding registered on the goja runtime explicitly panics with this message when len(call.Arguments) != 2; goja converts that panic into a JS exception, aborting template compilation/execution. The expected signature is ExportAs(key string, value any).
Source
Thrown at pkg/js/compiler/pool.go:195
}
for _, arg := range call.Arguments {
if out := stringify(arg, runtime); out != "" {
buff.WriteString(out)
}
}
return goja.Null()
},
})
// register exportAs function
_ = gojs.RegisterFuncWithSignature(runtime, gojs.FuncOpts{
Name: "ExportAs", // Export
Signatures: []string{"ExportAs(key string,value any)"},
Description: "Exports given value with specified key and makes it available in DSL and response",
FuncDecl: func(call goja.FunctionCall, runtime *goja.Runtime) goja.Value {
if len(call.Arguments) != 2 {
// this is how goja expects errors to be returned
// and internally it is done same way for all errors
panic(runtime.ToValue("ExportAs expects 2 arguments"))
}
key := call.Argument(0).String()
value := call.Argument(1)
opts.exports[key] = stringify(value, runtime)
return goja.Null()
},
})
}
// Internal purposes i.e generating bindings
func InternalGetGeneratorRuntime() *goja.Runtime {
runtime := gojapool.Get().(*goja.Runtime)
return runtime
}
func enableRequire(runtime *goja.Runtime) {
lazyRegistryInit()
_ = require.NewRegistry(require.WithLoader(newSourceLoader(runtime))).Enable(runtime)View on GitHub (pinned to 265b3a3dec)
Solutions
- Call ExportAs with exactly two arguments: a string key and any value, e.g. ExportAs('extracted', value).
- Lint template JS early — a syntax/arity check via the code protocol compile step (template-validate) catches it before a scan run.
- If you meant to export several values, issue one ExportAs call per key/value pair.
Example fix
// before
ExportAs('token'); // -> ExportAs expects 2 arguments
// after
ExportAs('token', extractedValue); Defensive patterns
Strategy: validation
Validate before calling
// in template JS: keep the arity check on your side
if (typeof key === 'string' && value !== undefined) {
ExportAs(key, value);
} Type guard
// JS guard before calling
const exportAs = (k, v) => { if (arguments.length !== 2) throw new TypeError('ExportAs(key, value)'); ExportAs(k, v); }; Try / catch
try { ExportAs('k', v); } catch (e) { if (String(e).includes('expects 2 arguments')) { /* fix call site arity */ } } Prevention
- ExportAs takes exactly (key, value) — one call per exported value.
- template-validate / lint code templates before scanning.
- Count arguments you pass, including trailing undefined ones.
When it happens
Trigger: Template JS calling ExportAs('k') with no value, ExportAs() with nothing, or ExportAs('k', v, extra); also passing extra undefined trailing arguments, since goja counts supplied arguments.
Common situations: Hand-writing code-protocol templates and forgetting the value; refactoring a helper into ExportAs and leaving an old single-argument call; copy-paste from examples that used a different export API.
Related errors
- panic: %s
- nuclei js runtime: program failed to terminate after interru
- invalid TicketRequest: %w
- invalid ASRepRoastRequest: %w
- invalid KerberoastRequest: %w
AI-assisted analysis of projectdiscovery/nuclei@265b3a3dec (2026-08-15).
Data as JSON: /api/errors/7c1df54fc58bfc86.
Report an issue: GitHub.