找不到模块:即使 sqlite.core.js 在 ./node_modules/react-native-sqlite-storage/lib/ 中,也无法解析 'react-native'
Module not found: Can't resolve 'react-native' even though sqlite.core.js is in the ./node_modules/react-native-sqlite-storage/lib/
我正在尝试通过在一个简单的应用程序上将 sqlite 与 react native 链接起来来开始......但不知何故不断出现以下错误:
我尝试了重新安装、重新链接、删除模块和 yarn start...
请帮忙!
找不到模块:即使 sqlite.core.js 文件位于 ./node_modules/react-native-sqlite-storage/lib/sqlite.core.js
中,也无法解析 'react-native'
错误:
"./node_modules/react-native-sqlite-storage/lib/sqlite.core.js
找不到模块:无法在 'C:\Users\accd8\Documents Expertise\React\TechTim\my-app\node_modules\react-native-sqlite-storage\lib'"
中解析 'react-native'
以下为浏览器:
Browser error message
显示图书馆的图片
node_modules/react-native-sqlite-storage/lib/sqlite.core.js
我的包裹杰森:
####{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-native-sqlite-storage": "^5.0.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"
]
}
}
####
APP.js
###import React from 'react'
import { useEffect } from 'react';
import { View, Text, Button } from 'react-native'
import SQLite from 'react-native-sqlite-storage'
const db = SQLite.openDatabase({
location: "default",
name: "SqliteDb"
}, () => {
console.log('başarılı')
}, (err) => {
console.log('hata')
})
const App = () => {
useEffect(() => {
db.transaction((tx) => {
tx.executeSql("CREATE TABLE IF NOT EXISTS students (ID INTEGER PRIMARY KEY AUTOINCREMENT , Name TEXT, AGE INTEGER)", [], (tx, result) => {
console.log('tx', tx)
console.log('result', result)
})
})
}, [])
const createRecord = () => {
for (let index = 0; index < 20; index++) {
const name = "Öğrenci" + index
const age = Math.floor(Math.random() * 50)
db.transaction((tx) => {
tx.executeSql('INSERT INTO students (Name,Age) VALUES(?,?)', [name, age], (tx, result) => {
console.log('tx', tx)
console.log('result', result)
})
})
}
}
const readRecord = () => {
db.transaction((tx) => {
tx.executeSql('SELECT * FROM students', [], (tx, result) => {
console.log('result', result)
for (let index = 0; index < result.rows.length; index++) {
console.log(result.rows.item(index))
}
})
})
}
const deleteRecord = () => {
db.transaction((tx) => {
tx.executeSql('DELETE FROM students where id = ? ', [1], (tx, result) => {
console.log(`tx`, tx)
console.log(`result`, result)
})
})
}
return (
<View>
<Button title="Ekle" onPress={createRecord} />
<Button title="Sil" onPress={deleteRecord} />
<Button title="Oku" onPress={readRecord} />
<Text>
React Native sqlite
</Text>
</View>
)
}
export default App
/*import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;
*/
您使用的是 React,而不是 React Native,这是两个不同的东西。 React 用于 Web,React Native 用于移动。您不能在 React 项目上安装 React Native 包。
此外,当前没有用于 Web 的 sqlite 实现。
但是您可以使用Local Storage将数据保存在客户端的浏览器中,或者将数据库的东西存储在服务器上。
我正在尝试通过在一个简单的应用程序上将 sqlite 与 react native 链接起来来开始......但不知何故不断出现以下错误: 我尝试了重新安装、重新链接、删除模块和 yarn start...
请帮忙! 找不到模块:即使 sqlite.core.js 文件位于 ./node_modules/react-native-sqlite-storage/lib/sqlite.core.js
中,也无法解析 'react-native'错误: "./node_modules/react-native-sqlite-storage/lib/sqlite.core.js 找不到模块:无法在 'C:\Users\accd8\Documents Expertise\React\TechTim\my-app\node_modules\react-native-sqlite-storage\lib'"
中解析 'react-native'以下为浏览器: Browser error message
显示图书馆的图片 node_modules/react-native-sqlite-storage/lib/sqlite.core.js
我的包裹杰森:
####{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-native-sqlite-storage": "^5.0.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"
]
}
}
####
APP.js
###import React from 'react'
import { useEffect } from 'react';
import { View, Text, Button } from 'react-native'
import SQLite from 'react-native-sqlite-storage'
const db = SQLite.openDatabase({
location: "default",
name: "SqliteDb"
}, () => {
console.log('başarılı')
}, (err) => {
console.log('hata')
})
const App = () => {
useEffect(() => {
db.transaction((tx) => {
tx.executeSql("CREATE TABLE IF NOT EXISTS students (ID INTEGER PRIMARY KEY AUTOINCREMENT , Name TEXT, AGE INTEGER)", [], (tx, result) => {
console.log('tx', tx)
console.log('result', result)
})
})
}, [])
const createRecord = () => {
for (let index = 0; index < 20; index++) {
const name = "Öğrenci" + index
const age = Math.floor(Math.random() * 50)
db.transaction((tx) => {
tx.executeSql('INSERT INTO students (Name,Age) VALUES(?,?)', [name, age], (tx, result) => {
console.log('tx', tx)
console.log('result', result)
})
})
}
}
const readRecord = () => {
db.transaction((tx) => {
tx.executeSql('SELECT * FROM students', [], (tx, result) => {
console.log('result', result)
for (let index = 0; index < result.rows.length; index++) {
console.log(result.rows.item(index))
}
})
})
}
const deleteRecord = () => {
db.transaction((tx) => {
tx.executeSql('DELETE FROM students where id = ? ', [1], (tx, result) => {
console.log(`tx`, tx)
console.log(`result`, result)
})
})
}
return (
<View>
<Button title="Ekle" onPress={createRecord} />
<Button title="Sil" onPress={deleteRecord} />
<Button title="Oku" onPress={readRecord} />
<Text>
React Native sqlite
</Text>
</View>
)
}
export default App
/*import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;
*/
您使用的是 React,而不是 React Native,这是两个不同的东西。 React 用于 Web,React Native 用于移动。您不能在 React 项目上安装 React Native 包。
此外,当前没有用于 Web 的 sqlite 实现。
但是您可以使用Local Storage将数据保存在客户端的浏览器中,或者将数据库的东西存储在服务器上。