在我的项目中我使用 typeorm ,我安装版本 0.3.20 但在项目 ionic 5 中使用 Angular 12 但现在我发现了这个错误:
“找不到模块:错误:无法解析'/node_modules/typeorm/browser/driver/react-native'中的'react-native-sqlite-storage'”
这是package.json:
{
"name": "test",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"lint": "ng lint",
"postinstall": "ngcc"
},
"private": true,
"dependencies": {
"@angular/animations": "^12.2.17",
"@angular/common": "^12.2.17",
"@angular/compiler": "^12.2.17",
"@angular/core": "^12.2.17",
"@angular/forms": "^12.2.17",
"@angular/platform-browser": "^12.2.17",
"@angular/platform-browser-dynamic": "^12.2.17",
"@angular/router": "^12.2.17",
"@ionic-native/core": "5.36.0",
"@ionic-native/network": "5.36.0",
"@ionic-native/splash-screen": "5.36.0",
"@ionic-native/sqlite": "^5.36.0",
"@ionic-native/status-bar": "5.36.0",
"@ionic/angular": "^5.9.4",
"@ionic/storage": "2.1.3",
"@ngui/auto-complete": "^3.0.0",
"@okta/okta-auth-js": "7.5.1",
"@types/lodash": "4.14.116",
"angular-oauth2-oidc": "12.1.0",
"angular2piwik": "0.1.5-beta",
"bootstrap": "5.3.3",
"classlist.js": "^1.1.20150312",
"cordova-android": "^11.0.0",
"cordova-plugin-device": "^2.0.3",
"cordova-plugin-statusbar": "^2.4.3",
"cordova-sqlite-storage": "^6.0.0",
"core-js": "^3.36.0",
"flickity": "2.1.2",
"font-awesome": "4.7.0",
"intl": "^1.2.5",
"ionic-plugin-keyboard": "^2.2.1",
"ionicons": "^5.0.0",
"jquery": "3.2.1",
"karma": "^6.0.0",
"karma-chrome-launcher": "^3.2.0",
"karma-coverage-istanbul-reporter": "^3.0.3",
"karma-jasmine": "^5.1.0",
"karma-jasmine-html-reporter": "^1.7.0",
"karma-junit-reporter": "^2.0.1",
"moment": "2.22.2",
"popper.js": "1.12.6",
"postcss-px2rem-exclude": "^0.0.6",
"puppeteer": "^5.2.1",
"reflect-metadata": "^0.2.1",
"rxjs": "~6.5.5",
"sqlite3": "^5.1.7",
"sw-toolbox": "3.6.0",
"tslib": "^2.3.0",
"typeorm": "^0.3.20",
"web-animations-js": "^2.2.5",
"zone.js": "0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "^12.0.0",
"@angular-eslint/builder": "^12.0.0",
"@angular-eslint/eslint-plugin": "^12.0.0",
"@angular-eslint/eslint-plugin-template": "^12.0.0",
"@angular-eslint/schematics": "^12.0.0",
"@angular-eslint/template-parser": "^12.0.0",
"@angular/cli": "^12.0.0",
"@angular/compiler-cli": "^12.0.0",
"@angular/language-service": "^12.0.0",
"@ionic/angular-toolkit": "^4.0.0",
"@types/jasmine": "~5.1.0",
"@types/node": "^14.14.31",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"babel-plugin-react-native-web": "^0.19.10",
"cordova-plugin-androidx-adapter": "^1.1.3",
"cordova-plugin-inappbrowser": "^5.0.0",
"cordova-plugin-ionic-webview": "^5.0.0",
"cordova-plugin-network-information": "^3.0.0",
"eslint": "^7.26.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jsdoc": "30.7.6",
"eslint-plugin-prefer-arrow": "1.2.2",
"typescript": "~4.2.3"
},
"description": "An Ionic project"
}
使用的节点版本是 v16.20.0,打字稿版本是 4.2.3
请问如何解决这个错误
我找到了解决方案。我阅读了typeorm的
package.json
,发现typeorm针对不同的环境(节点或浏览器)导入了不同的库。在某些情况下,我们希望使用数据库服务器端,但是,typeorm 被视为客户端依赖项,它会假设它在浏览器环境下并需要react-native 包。要处理这个问题,只需将其添加到您项目的 package.json
:
"browser": {
"typeorm": false
}