首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用cors-everywhere解析模块'net‘和'fs’

无法使用cors-everywhere解析模块'net‘和'fs’
EN

Stack Overflow用户
提问于 2017-05-10 19:38:35
回答 1查看 710关注 0票数 0

我想在任何地方使用cors-anywhere,但是我得到了这个错误:

代码语言:javascript
复制
ERROR in ./~/cors-anywhere/lib/cors-anywhere.js
Module not found: Error: Cannot resolve module 'net' in /Users/<username>/<project>/node_modules/cors-anywhere/lib
 @ ./~/cors-anywhere/lib/cors-anywhere.js 7:10-24

ERROR in ./~/cors-anywhere/lib/cors-anywhere.js
Module not found: Error: Cannot resolve module 'fs' in /<username>/<project>/node_modules/cors-anywhere/lib
 @ ./~/cors-anywhere/lib/cors-anywhere.js 20:4-17

我是通过

代码语言:javascript
复制
npm install cors-everywhere

我还将其添加到package.json中:

代码语言:javascript
复制
"cors-anywhere": "^0.4.0"

这是我的webpack.config:

代码语言:javascript
复制
module.exports = {
  entry: ['babel-polyfill', './app/index.js'],
  output: {
    path: './build',
    // if the above line does not work, try `path: __dirname + '/build'`
    filename: 'bundle.js',
    target: 'node'
  },
  module: {
    loaders: [
      {
        test: /\.js$/, // a regular expression that catches .js files
        exclude: /node_modules/,
        loader: 'babel-loader'
      }
    ]
  },
  devServer: {
    port: 3000, // most common port
    contentBase: './build',
    inline: true
  }
}

我试着找到一个解决方案,但没有什么真正有帮助的。我还转储了所有的node-module,并再次运行npn install,再一次安装cors。

Afaik这个"fs“和"net”是node的基本部分吗?所以我有点搞不懂为什么他们会在这里消失...

如果有人有主意的话就太好了--谢谢!

致以最好的问候,丹尼尔

EN

回答 1

Stack Overflow用户

发布于 2017-05-10 19:47:54

target属性未正确放置,应将其放置在对象根目录中,而不是output

代码语言:javascript
复制
entry: ['babel-polyfill', './app/index.js'],
output: {
  path: './build',
  // if the above line does not work, try `path: __dirname + '/build'`
  filename: 'bundle.js',
},
target: 'node',
...
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43891413

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档