我正在尝试将https://github.com/andpor/react-native-sqlite-storage实施到我的 react native 项目(适用于 Android)中。
这是我的 React Native 版本:
"react-native": "0.64.1"
这是我的步骤:
npm install --save react-native-sqlite-storage
我认为我不需要额外的步骤,因为我有 >0.6 版本的 React Native。所以我决定用那个库编写一些东西。我做进口
import SQLite from 'react-native-sqlite-storage';
我收到了那个错误:
[Info] 06-07 09:00:30.160 6927 6983 E ReactNativeJS: { [Error: InternalError Metro has encountered an error: While trying to resolve module `react-native-sqlite-storage` from file `c:\Users\karol.wisniewski\happybaby\HappyBaby\app\components\Test\HomeScreen.component.js`, the package `c:\Users\karol.wisniewski\happybaby\HappyBaby\node_modules\react-native-sqlite-storage\package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`c:\Users\karol.wisniewski\happybaby\HappyBaby\node_modules\react-native-sqlite-storage\sqlite.js`. Indeed, none of these files exist:
06-07 09:00:30.160 6927 6983 E ReactNativeJS:
06-07 09:00:30.160 6927 6983 E ReactNativeJS: * c:\Users\karol.wisniewski\happybaby\HappyBaby\node_modules\react-native-sqlite-storage\sqlite.js(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
06-07 09:00:30.160 6927 6983 E ReactNativeJS: * c:\Users\karol.wisniewski\happybaby\HappyBaby\node_modules\react-native-sqlite-storage\sqlite.js\index(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx): c:\Users\karol.wisniewski\happybaby\HappyBaby\node_modules\metro\src\node-haste\DependencyGraph.js (436:17)
06-07 09:00:30.160 6927 6983 E ReactNativeJS:
06-07 09:00:30.160 6927 6983 E ReactNativeJS: [0m [90m 434 |[39m[0m
06-07 09:00:30.160 6927 6983 E ReactNativeJS: [0m [90m 435 |[39m [36mif[39m (error [36minstanceof[39m [33mInvalidPackageError[39m) {[0m
06-07 09:00:30.160 6927 6983 E ReactNativeJS: [0m[31m[1m>[22m[39m[90m 436 |[39m [36mthrow[39m [36mnew[39m [33mPackageResolutionError[39m({[0m
06-07 09:00:30.160 6927 6983 E ReactNativeJS: [0m [90m |[39m [31m[1m^[22m[39m[0m
06-07 09:00:30.160 6927 6983 E ReactNativeJS: [0m [90m 437 |[39m packageError[33m:[39m error[33m,[39m[0m
06-07 09:00:30.160 6927 6983 E ReactNativeJS: [0m [90m 438 |[39m originModulePath[33m:[39m [36mfrom[39m[33m,[39m[0m
06-07 09:00:30.160 6927 6983 E ReactNativeJS: [0m [90m 439 |[39m targetModuleName[33m:[39m to[0m]
06-07 09:00:30.160 6927 6983 E ReactNativeJS: preventSymbolication: true,
06-07 09:00:30.160 6927 6983 E ReactNativeJS: line: 33240,
06-07 09:00:30.160 6927 6983 E ReactNativeJS: column: 26,
06-07 09:00:30.160 6927 6983 E ReactNativeJS: sourceURL: 'http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.happybaby&modulesOnly=false&runModule=true' }
我在这里找到了解决方案但是,这个包本身指定了一个无法解析的“主”模块字段,我metro.config.js
看起来像这样:
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
}),
},
resolver: {
sourceExts: ['jsx', 'js', 'ts', 'tsx']
},
};
但我仍然有同样的错误。
你有什么解决方案,或者我在配置这个库或其他东西时犯了一个错误?