I am using composer embeded to test my code, when I add request function to interact other server.ReferenceError: require is not defined

筅森魡賤 提交于 2019-12-14 03:08:52

问题


I was writing composer test.In my origin codes, the logic.js include request.post which interact with other server. I add var request = require('request') in the beginning to avoid error which is "error 'request' is not defined". in this way, I can translate the package into a .bna file, and work well. But when I try to write some unit test with 'embeded', the error came up with ReferenceError: require is not defined. I add the 'require' package in my package.json file.


回答1:


this is because that 'eslint' is complaining it doesn't know what to do with request when you run npm test etc. We shoud add the comment like

/* global getAssetRegistry getFactory emit request */

follow the example: https://github.com/hyperledger/composer-sample-networks/blob/master/packages/basic-sample-network/lib/sample.js#L15



来源:https://stackoverflow.com/questions/52377517/i-am-using-composer-embeded-to-test-my-code-when-i-add-request-function-to-inte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!