[ https://issues.apache.org/jira/browse/COUCHDB-1961?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13846506#comment-13846506 ]
James Dingwall commented on COUCHDB-1961: ----------------------------------------- I have quite a lot of code that I'd need to rewrite but I'll do that your method is the correct way to structure the commonjs modules. I just preferred writing: require('views/lib/docUtil'); to var docUtil = require('views/lib/docUtil').docUtil; However I do see that the http://wiki.commonjs.org/wiki/Modules/1.1.1 gives code which looks like your rewrite as an example. > CouchDB Module Cache Misbehaving > -------------------------------- > > Key: COUCHDB-1961 > URL: https://issues.apache.org/jira/browse/COUCHDB-1961 > Project: CouchDB > Issue Type: Bug > Components: JavaScript View Server > Affects Versions: 1.3.1, 1.4.0, 1.5.0 > Reporter: James Dingwall > > The module cache is breaking update functions which share a common module via > require(). Disabling the caching by adding || true in main.js at line 1174 > (CouchDB 1.5.0) resolves the problem. With this disabled then both curl > commands in the example pass. > This code was introduced in https://issues.apache.org/jira/browse/COUCHDB-1075 > Here is a complete test case design document which demonstrates the problem. > { > "_id": "_design/ptest", > "updates": { > "two": "function(doc, req) > {\n\trequire('views/lib/docUtil');\n\n\tif(!doc) {\n\t\tdoc = > {};\n\t}\n\n\tdoc._id = 'two';\n\n\tdoc.meta = > docUtil.metaCreate();\n\n\treturn([doc, JSON.stringify(doc, undefined, > 2)]);\n}", > "one": "function(doc, req) > {\n\trequire('views/lib/docUtil');\n\n\tif(!doc) {\n\t\tdoc = > {};\n\t}\n\n\tdoc._id = 'one';\n\n\tdoc.meta = > docUtil.metaCreate();\n\n\treturn([doc, JSON.stringify(doc, undefined, > 2)]);\n}" > }, > "language": "javascript", > "views": { > "lib": { > "docUtil": "(function(global) {\n\nvar _metaCreate = function() > {\n\treturn({\n\t\ta: 'create',\n\t\tb: 'bbbb'\n\t});\n};\n\nvar _metaModify > = function() {\n\treturn({\n\t\ta: 'modify',\n\t\tb: > 'bbbb'\n\t});\n};\n\nglobal.docUtil = {\n\tmetaCreate: > _metaCreate,\n\tmetaModify: _metaModify\n};\n\nlog('require > docUtil');\n\n})(exports.docUtil = this)" > } > }, > "type": "design/ptest" > } > Call the update functions like: > curl -X POST http://couchdb:5984/zydev/_design/ptest/_update/one - creates a > document > curl -X POST http://couchdb:5984/zydev/_design/ptest/_update/two - fails -- This message was sent by Atlassian JIRA (v6.1.4#6159)