我试图导入mssql我有一个js文件可以正常工作但是我需要这样做以便我可以在react js环境中调用该函数而不仅仅是节点
import React, { Component } from 'react';
import TextInput from '../SmallBits/FormItems/TextInput';
import sql from 'mssql';
//or
var sql = require('mssql');
var dbConfig = {
server: 'localhost',
database: 'TestDB',
user: 'andy',
password: 'andy',
port: 1433
};
export default class LeftBox extends Component {
constructor(props){
super(props);
this.state = {
name: '',
forename: '',
surname: '',
caseID: '',
address: ''
}
this.handleSurnameChange = this.handleSurnameChange.bind(this);
this.handleForenameChange = this.handleForenameChange.bind(this);
this.handleCaseIDChange = this.handleCaseIDChange.bind(this);
this.handleAddressChange = this.handleAddressChange.bind(this);
}
loadEmployees() {
var dbConn = new sql.ConnectionPool(dbConfig);
dbConn.connect().then(function () {
var request = new sql.Request(dbConn);
request.query("select * from EmployeeTable").then(function (recordSet) {
console.log(recordSet);
return recordSet;
dbConn.close();
}).catch(function (err) {
console.log(err);
dbConn.close();
});
}).catch(function (err) {
console.log(err);
});
}
所有被调用的所有代码都是顶级机器人的import和require语句,这给我一个模块未找到的错误:无法解决' mssql'在&C; \ Users \ wilsona.CHECKMATE \ Desktop \ reactapp \ Workspace \ savvy-crm-test \ src \ components \ Parts \ Boxes'即使全局安装了mssql,我也应该在本地安装