【问题标题】:Cannot resolve module 'net' & 'fs' using cors-everywhere无法使用 cors-everywhere 解析模块“net”和“fs”
【发布时间】:2019-02-16 01:15:57
【问题描述】:

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

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”是节点的基本部分吗?所以我有点困惑为什么他们应该在这里失踪......

如果有人有想法,那就太好了 - 谢谢!

最好的问候, 丹尼尔

【问题讨论】:

  • 我有一个相关问题,但对我来说,我的构建工具似乎无法正常工作。当我npm install 或安装其他 npm 模块时,我在命令行中的 npm 中遇到了许多错误。删除 node_modules 目录后运行 npm install 时是否出现任何错误?

标签: javascript webpack cors backend cors-anywhere


【解决方案1】:

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',
...

【讨论】:

    猜你喜欢
    • 2018-07-20
    • 2016-12-27
    • 2020-04-18
    • 2022-06-27
    • 2022-08-05
    • 2022-11-12
    • 2022-06-20
    • 2021-08-01
    • 2018-06-29
    相关资源
    最近更新 更多