首页 > 解决方案 > 无法从“node_modules\react-simple-chatbot”解析“styled-components”

问题描述

我正在尝试使用 expo cli 运行我的反应应用程序,并在构建 bundle.js 时出现以下错误。

以下是我的 App.js:

import React, { Component } from 'react';
import ChatBot from 'react-simple-chatbot';

let withTextToSpeech = [
  {
    id: '1',
    component: <TextToSpeech msg="Hi" />,
    trigger: '2',
  },
  {
    id: '2',
    user: true,
    trigger: '3',
  },
  {
    id: '3',
    component: <TextToSpeech msg='What is your name?' />,
    trigger: '4',
  },
  {
    id: '4',
    user: true,
    trigger: '5',
  },
  {
    id: '5',
    component: <TextToSpeech msg = 'Nice to meet you!' />,
    trigger: 6,
  },
  {
    id: '6',
    component: <TextToSpeech msg='How can i help you?' />,
    trigger: 'search',
  },
  {
    id: 'search',
    user: true,
    trigger: '7',
  }
]

let withoutTextToSpeech = [
  {
    id: '1',
    message: 'hi',
    trigger: '2',
  },
  {
    id: '2',
    user: true,
    trigger: '3',
  },
  {
    id: '3',
    message: 'What is your name?',
    trigger: '4',
  },
  {
    id: '4',
    user: true,
    trigger: '5',
  },
  {
    id: '5',
    message: 'Hi {previousValue}, nice to meet you!',
    trigger: 6,
  },
  {
    id: '6',
    message: 'How can i help you?',
    trigger: 'search',
  },
  {
    id: 'search',
    user: true,
    trigger: '7',
  }
]



class App extends Component {

  constructor( props ){
    super( props )

    this.state= {
      textToSpeech: true,
      steps : withTextToSpeech,
      sessionId: sessionId
    }
    withTextToSpeech.push(ChatMessageElement)
    withoutTextToSpeech.push(ChatMessageElement)
  }

  render() {
    console.log(this.state.textToSpeech)
    return (
      <div className="App">
        <ChatBot
          headerTitle="ChatBot"
          recognitionEnable={true}
          steps={this.state.textToSpeech ? withTextToSpeech : withoutTextToSpeech}
        />
      </div>
    );
  }
}

export default App;

帮助将不胜感激。

标签: reactjsreact-nativechatbotstyled-components

解决方案


yarn add styled-components


import styled from 'styled-components'

推荐阅读