Webpack捆绑的React应用中的node-mssql错误 [英] Errors with node-mssql in a webpack-bundled React app

查看:145
本文介绍了Webpack捆绑的React应用中的node-mssql错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我尝试使用 node-mssql 库时,我的React应用程序都无法构建.在客户端执行此操作很重要,因为我必须从旧的IIS服务器提供此应用程序.在Webpack浏览器捆绑中执行似乎需要其他配置.也许是某种Polyfill?我在任何地方都找不到任何帮助-我真的可以使用一些建议.

My React app fails to build whenever I try to use the node-mssql library. It's important that I do this on the client side, since I have to serve this app from an old IIS server. It seems that executing in Webpack browser bundle requires additional configuration. Some kind of Polyfill maybe? I can't find any help on this anywhere -- I could really use some advice.

构建错误和警告为:

    WARNING in ./~/mssql/lib/tds-fix.js
    Module not found: Error: Cannot resolve module 'tds/package.json' in /Users/hills/upload-covers/node_modules/mssql/lib
     @ ./~/mssql/lib/tds-fix.js 6:8-35

    WARNING in ./~/mssql/lib/tds-fix.js
    Module not found: Error: Cannot resolve module 'tds/lib/tds-constants.js' in /Users/hills/upload-covers/node_modules/mssql/lib
     @ ./~/mssql/lib/tds-fix.js 13:4-39

    WARNING in ./~/mssql/lib/tds-fix.js
    Module not found: Error: Cannot resolve module 'tds' in /Users/hills/upload-covers/node_modules/mssql/lib
     @ ./~/mssql/lib/tds-fix.js 14:4-18

    ERROR in ./~/mssql/lib/msnodesql.js
    Module not found: Error: Cannot resolve module 'msnodesql' in /Users/hills/upload-covers/node_modules/mssql/lib
     @ ./~/mssql/lib/msnodesql.js 9:14-34

    ERROR in ./~/mssql/lib/msnodesqlv8.js
    Module not found: Error: Cannot resolve module 'msnodesqlv8' in /Users/hills/upload-covers/node_modules/mssql/lib
     @ ./~/mssql/lib/msnodesqlv8.js 9:14-36

    ERROR in ./~/mssql/lib/tds.js
    Module not found: Error: Cannot resolve module 'tds' in /Users/hills/upload-covers/node_modules/mssql/lib
     @ ./~/mssql/lib/tds.js 9:8-22

    ERROR in ./~/tedious/lib/connection.js
    Module not found: Error: Cannot resolve module 'net' in /Users/hills/upload-covers/node_modules/tedious/lib
     @ ./~/tedious/lib/connection.js 25:13-27

    ERROR in ./~/tedious/lib/instance-lookup.js
    Module not found: Error: Cannot resolve module 'dgram' in /Users/hills/upload-covers/node_modules/tedious/lib
     @ ./~/tedious/lib/instance-lookup.js 3:12-28

    ERROR in ./~/tedious/lib/message-io.js
    Module not found: Error: Cannot resolve module 'tls' in /Users/hills/upload-covers/node_modules/tedious/lib
     @ ./~/tedious/lib/message-io.js 11:10-24

这是我的webpack配置:

Here is my webpack config:

    var path = require('path');
    var webpack = require('webpack');
    var HtmlWebpackPlugin = require('html-webpack-plugin');

    module.exports = {
      devtool: 'eval-source-map',
      entry: [
        'webpack-hot-middleware/client?reload=true',
        path.join(__dirname, 'app/main.js')
      ],
      output: {
        path: path.join(__dirname, '/dist/'),
        filename: '[name].js',
        publicPath: '/'
      },
      plugins: [
        new HtmlWebpackPlugin({
          template: 'app/index.tpl.html',
          inject: 'body',
          filename: 'index.html'
        }),
        new webpack.optimize.OccurenceOrderPlugin(),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin(),
        new webpack.DefinePlugin({
          'process.env.NODE_ENV': JSON.stringify('development')
        })
      ],
      module: {
        loaders: [{
          test: /\.js?$/,
          exclude: /node_modules/,
          loader: 'babel',
          query: {
            "presets": ["react", "es2015", "stage-0", "react-hmre"]
          }
        }, {
          test: /\.json?$/,
          loader: 'json'
        }, {
          test: /\.css$/,
          loader: 'style!css?modules&localIdentName=[name]---[local]---[hash:base64:5]'
        }]
      }
    };

谢谢.

推荐答案

MSSQL服务器连接库不是客户端javascript库.即使您编写了自己的库,也绝对无法通过Web浏览器建立TCP SQL连接.

MSSQL server connection libraries are not client-side javascript libraries. There is absolutely no way you can make TCP SQL connections from a web browser, even if you wrote your own library.

出于安全原因,您永远都不想允许客户端访问SQL Server.您需要加速服务器端环境(例如Node/Express),才能向客户端应用程序公开API.

For security reasons, you would never want to allow client-side access to the SQL Server. You need to spin up server-side environment (e.g. Node/Express) to expose an API to the client applications.

这篇关于Webpack捆绑的React应用中的node-mssql错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆