【问题标题】:Module not found - trying to use react-native and react-native-tts未找到模块 - 尝试使用 react-native 和 react-native-tts
【发布时间】:2021-07-04 01:11:31
【问题描述】:

当这个模块不工作时,我很难弄清楚。每次我尝试运行我的代码时,都会出现以下编译失败错误:

./node_modules/react-native-tts/index.js
Module not found: Can't resolve 'react-native' in 'C:\Users\Anthony\Desktop\klementine\node_modules\react-native-tts'

我一直在尝试寻找一个模块来使文本转语音工作,只需为函数提供一个简单的字符串而不是使用 .wav 文件,这就是我尝试使用 react-native-tts 的原因。否则我也会接受任何人的建议。

这是我启动应用程序的 index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './components/App';
import reportWebVitals from './reportWebVitals';
import { ThemeProvider } from '@material-ui/core/styles'
import theme from "./theme"


ReactDOM.render(
  <React.StrictMode>
    <ThemeProvider theme={theme}>
      <App />
    </ThemeProvider>
  </React.StrictMode>,
  document.getElementById('root')
);

这是我的应用页面

import { BrowserRouter as Router, Switch, Route } from "react-router-dom"
import { Link as RouterLink } from 'react-router-dom';
import Badge from '@material-ui/core/Badge';
import React from "react"
import Home from "./Home"
import Two from "./Two"
import Three from "./Three"
import Eat from "./Eat/Eat"
import NativeSpeech from "./NativeSpeech"

function App() {


  return (

    <div>
      <Router>
        <Switch>
          <Route exact path="/" component={Home}/>
          <Route path="/Two" component={Two}/>
          <Route path="/Three" component={Three}/>
          <Route path="/Eat" component={Eat}/>
          <Route path="/NativeSpeech" component={NativeSpeech}/>
        </Switch>
      </Router>
    </div>
  );
}

export default App;

这是我的包,其中显示了我的依赖项:

{
  "name": "klementine",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^4.11.4",
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "node": "^16.4.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-native": "^0.64.2",
    "react-native-tts": "^4.1.0",
    "react-scripts": "4.0.3",
    "web-vitals": "^1.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

【问题讨论】:

  • react-native-tts 是一个专门为 react-native 开发的库。 react 和 react-native 是不一样的。 React 是为 web 设计的,而 React Native 是为移动端设计的。但是,您也可以使用为 web 制作的 speak-tts 库。 npmjs.com/package/speak-tts
  • 非常感谢。这很有帮助,帮助我转移注意力。!

标签: javascript reactjs react-native


【解决方案1】:

找不到错误模块也可能是因为可能的拼写错误而不是语法错误,而是因为使用 pip 的语法不同。 例如: 我遇到的错误:找不到模块 SpeechRecognition 我已安装的软件包: pip install speechReconotion 并已成功安装 错误是因为在代码导入中,正确的代码是 import speech_recognition 并且我写了 import speechRecognition ,显然我已经安装了 speechRecogntion 。因此,请尝试为您的模块编写不同的语法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 2018-08-05
    • 2019-09-06
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    相关资源
    最近更新 更多