Утомительный пакет, выдающий ошибку "undefined не является функцией" с es6,React,webpack
Я пытаюсь подключиться к удаленному серверу MySQL, используя строки подключения с помощью утомительной библиотеки. Я преобразовал весь свой код из реагировать на реаги-ES6. когда я пытаюсь установить соединение, как показано ниже, я получаю сообщение об ошибке "undefined не является функцией".
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'));
Я не могу установить соединение. Возможно, может быть синтаксическая ошибка, поскольку я новичок в этом.
1 ответ
Это потому, что, вероятно, объект Connection не должен использоваться в браузере. Потому что это подключается к БД или что-то.
Вы должны создать модуль jS для взаимодействия с этим подключением через вызовы Ajax и импортировать его в свой компонент.