“错误”;LexAudio.conversation不是构造函数;。React组件调用普通javascript

“错误”;LexAudio.conversation不是构造函数;。React组件调用普通javascript,javascript,reactjs,amazon-web-services,react-native,amazon-lex,Javascript,Reactjs,Amazon Web Services,React Native,Amazon Lex,下面是调用外部javascript进行对话的React组件。呼叫新LexAudio时出现问题。对话(…) 将外部js库导入react组件的最佳方式是什么 class MyComponent extends Component { startConversation() { AWS.config.credentials = new AWS.Credentials('', '', null); AWS.config.region = 'us-east-1';

下面是调用外部javascript进行对话的React组件。呼叫新LexAudio时出现问题。对话(…) 将外部js库导入react组件的最佳方式是什么

class MyComponent extends Component {

  startConversation() {
    AWS.config.credentials =  new AWS.Credentials('', '', null);
      AWS.config.region = 'us-east-1';
      var waveform = require('./renderer_1.js');
      var waveform = window.Waveform();
      var config = {
          lexConfig: { botName: 'testbot' }
      };
      var message = document.getElementById('message');
      var LexAudio = require('./aws-lex-audio.js');
      var conversation =  new LexAudio.conversation(config, function (state) {

          message.textContent = state + '...';
          if (state === 'Listening') {
              waveform.prepCanvas();
          }
          if (state === 'Sending') {
              waveform.clearCanvas();
          }
      }, function (data) {
          console.log('Transcript: ', data.inputTranscript, ", Response: ", data.message);
      }, function (error) {
          //message.textContent = error;
      }, function (timeDomain, bufferLength) {
          waveform.visualizeAudioBuffer(timeDomain, bufferLength);
      });
      conversation.advanceConversation();
  }
  render() {
    return (
      <div className='Hello'>`enter code here`
        <meta charSet="UTF-8" />
        <link rel="stylesheet" href="style.css" />
        <div className="audio-control" onClick={this.startConversation}>
          <p id="audio-control" className="white-circle">
            <img  alt="new" src="./lex.png" />
            <canvas className="visualizer" />
          </p>
          <p><span id="message" /></p>
        </div>
      </div>
    );
  };
}

export default MyComponent;
类MyComponent扩展组件{
startConversation(){
AWS.config.credentials=新的AWS.credentials('','',null);
AWS.config.region='us-east-1';
var波形=require('./renderer_1.js');
var波形=window.waveform();
变量配置={
lexConfig:{botName:'testbot'}
};
var message=document.getElementById('message');
var LexAudio=require('./aws lex audio.js');
var conversation=new LexAudio.conversation(配置、函数(状态){
message.textContent=状态+'…';
如果(状态=='Listening'){
waveform.prepCanvas();
}
如果(状态==‘发送’){
waveform.clearCanvas();
}
},函数(数据){
console.log('Transcript:',data.inputTranscript',Response:',data.message);
},函数(错误){
//message.textContent=错误;
},函数(时域,缓冲区长度){
波形。音频缓冲区(时域,缓冲区长度);
});
会话。高级会话();
}
render(){
返回(
`在这里输入代码`

); }; } 导出默认MyComponent;

谢谢您的帮助。

尝试导入页面顶部的LexAudio。你们的大部分进口货都应该放在这里

比如:

从“/aws lex audio.js”导入LexAudio

而不是:

var LexAudio=require('./aws lex audio.js')