2015-07-29 5 views
-2

Я пытаюсь подключиться к удаленному серверу mysql, используя строки подключения с помощью утомительной библиотеки. Я преобразовал весь свой код из реакции на реакцию-es6. , когда я пытаюсь сделать подключение, как показано ниже, я получаю сообщение об ошибке «undefined is not a function».Условный пакет, дающий ошибку «undefined не является функцией» с es6, React, webpack

class APP extends React.Component { 
    constructor(props) { 
     alert("hai"); 
     console.log("hai"); 
     super(props); 
     this.state = { 
      result: [], 
      RecNo: "" 
     }; 
    } 
    getZipData(){ 
     alert("hello"); 
     var Connection = require('tedious').Connection; 
     console.log("connection:"+Connection) 
     Request = require('tedious').Request; 
     console.log("request:"+Request); 
     var config = { 
      userName: 'xx', 
      password: 'xxxxxx', 
      server: 'xxxxxxxxx', 
      options: { 
       database: 'xxxxxxx' 
      } 
     }; 
     alert("shaik"+JSON.stringify(config)); 
     var connection = new Connection(config); //getting error here 
     alert("connected") 
     connection.on('connect',(err)=> { 
      console.log("connected"); 
      if (err) { 
       console.log(err) 
      } 
      //executeStatement(); 
      var sql = "SELECT * FROM xxxx"; 
      return new Promise(
       function(resolve,reject){ 
        var data = []; 
        var request = new Request(sql,[],(row)=>{ 
          data.push(row); 
         }, 
         (error)=>{ 
          if(error){ 
           reject(error); 
          }else{ 
           resolve(data); 
          } 
         }); 
       } 
      ) 
      connection.execSql(request); 
      console.log("hai:") 
     }); 
    } 

     componentWillMount() { 
    this.getZipData() 
     alert("data:"); 
    } 
    render(){ 
     return(
      <p>Hello</p> 
     ) 
    } 
} 
React.render(<APP/>,document.getElementById('app')); 

Я не могу установить соединение. Возможно, может возникнуть синтаксическая ошибка, так как я новичок в этом.

+0

В какой строке вы получаете эту ошибку? –

+0

var connection = new Connection (config); –

+0

В этом случае 'require ('tedious'). Connection' возвращает' undefined'. –

ответ

0

Это связано с тем, что объект Connection не должен использоваться в браузере. Потому что он подключается к БД или что-то в этом роде.

Вы должны создать модуль jS для взаимодействия с этим соединением через вызовы Ajax и импортировать его в свой компонент.