0

我想在任何地方使用 cors,但我得到了那个错误:

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

我通过安装它

npm install cors-everywhere

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

"cors-anywhere": "^0.4.0"

那是我的 webpack.config:

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
  }
}

我试图找到一个解决方案,但没有任何帮助。我还转储了所有节点模块并再次运行 npn install,再次安装 cors-everwhere。

Afaik 这个“fs”和“net”是节点的基本部分吗?所以我有点困惑为什么他们应该在这里失踪......

如果有人有想法会很棒 - 谢谢!

最好的问候,丹尼尔

4

1 回答 1

0

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

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',
...
于 2017-05-10T11:47:54.163 回答