Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

referenceError when using require in _view filter for _changes #2769

Open
ghost opened this issue Apr 9, 2020 · 1 comment
Open

referenceError when using require in _view filter for _changes #2769

ghost opened this issue Apr 9, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Apr 9, 2020

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

apache/couchdb:3.0.0

Additional Context

n/a

@Minecraftschurli
Copy link

Minecraftschurli commented Apr 4, 2022

I have the same issue with a normal filter function (using the docker image 3.2.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant