Я пытаюсь подключиться к удаленному серверу 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'));
Я не могу установить соединение. Возможно, может возникнуть синтаксическая ошибка, так как я новичок в этом.
В какой строке вы получаете эту ошибку? –
var connection = new Connection (config); –
В этом случае 'require ('tedious'). Connection' возвращает' undefined'. –