couchdb
couchdb copied to clipboard
referenceError when using require in _view filter for _changes
Description
Given a view function using CommonJS to require
something,
when using that view as a filter for _changes
(see docs),
then the response is a 500 status with a referenceError logged like below:
{<<"ReferenceError">>,{[]}} [
{couch_os_process,prompt,2,[{file,"src/couch_os_process.erl"},{line,59}]},
{couch_query_servers,proc_prompt,2,[{file,"src/couch_query_servers.erl"},{line,520}]},
{couch_query_servers,with_ddoc_proc,2,[{file,"src/couch_query_servers.erl"},{line,514}]},
{couch_query_servers,filter_view,3,[{file,"src/couch_query_servers.erl"},{line,486}]},
{couch_changes,filter,3,[{file,"src/couch_changes.erl"},{line,236}]},
{fabric_rpc,changes_enumerator,2,[{file,"src/fabric_rpc.erl"},{line,514}]},
{couch_bt_engine,drop_reductions,4,[{file,"src/couch_bt_engine.erl"},{line,1177}]},
{couch_btree,stream_kv_node2,8,[{file,"src/couch_btree.erl"},{line,849}]}
]
Steps to Reproduce
Create a design doc like this:
{
"_id": "_design/MyDesignDoc",
"views": {
"myView": {
"map": "function(doc) {\n var myLib = require('views/lib/myLib');\n log(myLib.myExport); // expecting to log 'foo'\n emit(doc._id, 1);\n}"
},
"lib": {
"myLib": "exports.myExport = \"foo\";"
}
}
}
Follow URL like this:
myDb/_changes?filter=_view&view=MyDesignDoc/myView
Expected Behaviour
Seeing changes filtered by the map function from that view.
Your Environment
Additional Context
n/a
I have the same issue with a normal filter function (using the docker image 3.2.1)