描述你的问题
项目使用了fetch.js,用webpack打包报错Cannot resolve module 'dns'
贴上相关代码
require('fetch');
贴上报错信息
WARNING in ./~/fetch/~/encoding/lib/iconv-loader.js
Critical dependencies:
9:12-34 the request of a dependency is an expression
@ ./~/fetch/~/encoding/lib/iconv-loader.js 9:12-34
ERROR in ./~/fetch/lib/fetch.js
Module not found: Error: Cannot resolve module 'dns' in /home/tigerb/github/easy-vue/node_modules/fetch/lib
@ ./~/fetch/lib/fetch.js 8:10-24
ERROR in ./~/fetch/lib/fetch.js
Module not found: Error: Cannot resolve module 'net' in /home/tigerb/github/easy-vue/node_modules/fetch/lib
@ ./~/fetch/lib/fetch.js 12:10-24
阿神2017-04-10 17:03:22
log里面不是说出现了循环依赖么?
你检查下你的webpack的resolve里面配置是否正确呗。
PS: 你的fetch.js是个什么东东?怎么会调用dns和net这两个node模块的?这两个模块应该没法跑在浏览器里面吧。如果你是在编写服务端的node,那没必要用webpack
巴扎黑2017-04-10 17:03:22
你可能需要这个:https://github.com/matthew-andrews/isomorphic-fetch
或者: https://github.com/github/fetch