typeorm / react-native-example

Example project to demonstrate TypeORM with React Native.
68 stars 29 forks source link

Unable to resolve module path from C:\Workspace\budgeter\node_modules\typeorm\platform\PlatformTools.js #10

Open AshleyEke opened 1 year ago

AshleyEke commented 1 year ago

I'm trying to get the example working with the following versions:

"react-native": "0.70.3",
"react-native-sqlite-storage": "^6.0.1",
"typeorm": "^0.3.12",
"@babel/core": "^7.12.9",
"@babel/plugin-proposal-decorators": "^7.20.13",
"@babel/runtime": "^7.12.5",

When I run react-native run android, metro reports the following error:

error: Error: Unable to resolve module path from ...\node_modules\typeorm\platform\PlatformTools.js: path could not be found within the project or in these directories:
  node_modules\typeorm\node_modules
  node_modules
  3 | exports.PlatformTools = exports.Writable = exports.Readable = exports.EventEmitter = exports.ReadStream = void 0;
  4 | const tslib_1 = require("tslib");
> 5 | const path = tslib_1.__importStar(require("path"));
    |                                            ^
  6 | const fs = tslib_1.__importStar(require("fs"));
  7 | const dotenv_1 = tslib_1.__importDefault(require("dotenv"));
  8 | const chalk_1 = tslib_1.__importDefault(require("chalk"));
    at ModuleResolver.resolveDependency (...\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:178:15)
    at DependencyGraph.resolveDependency (...\node_modules\metro\src\node-haste\DependencyGraph.js:264:43)
    at Object.resolve (...\node_modules\metro\src\lib\transformHelpers.js:170:21)
    at resolveDependencies (...\node_modules\metro\src\DeltaBundler\graphOperations.js:466:33)
    at processModule (...\node_modules\metro\src\DeltaBundler\graphOperations.js:232:31)
    at async addDependency (...\node_modules\metro\src\DeltaBundler\graphOperations.js:361:18)
    at async Promise.all (index 0)
    at async processModule (...\node_modules\metro\src\DeltaBundler\graphOperations.js:279:3)
    at async addDependency (...\node_modules\metro\src\DeltaBundler\graphOperations.js:361:18)
    at async Promise.all (index 1)

My babel.config.js consists of the following

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    'babel-plugin-transform-typescript-metadata',
    ['@babel/plugin-proposal-decorators', {version: "legacy"}]
  ]
};

My tsconfig.json consists of the following

{
  "extends": "@tsconfig/react-native/tsconfig.json",     /* Recommended React Native TSConfig base */
  "compilerOptions": {
    "strict": false,
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    /* Visit https://aka.ms/tsconfig.json to read more about this file */

    /* Completeness */
    "skipLibCheck": true                                 /* Skip type checking all .d.ts files. */
  }
}

Some of the functions used in this example are deprecated, so my app code looks like this:

const db = new DataSource({
    type: 'react-native',
    database: 'budgeteer',
    location: 'default',
    logging: ['error', 'query', 'schema'],
    entities: [
      Category
    ]
  });

const category = new Category();
category.name = "Test";

const categoryRepo = db.getRepository(Category);
await categoryRepo.save(category);

As far as I can tell though, it isn't getting as far as instantiating the data source.