question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeORM pulls Native Modules on Browser import when using Metro

See original GitHub issue

TypeORM pulls Native Modules on Browser import when using Metro

[X] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [ ] mysql / mariadb [ ] oracle [ ] postgres [ ] cockroachdb [ ] sqlite [ ] sqljs [X] react-native [X] expo

TypeORM version:

[X] latest [X] @next [X] 0.2.8 (or put your version here)

Steps to reproduce or a small repository showing the problem:

I have tested multiple versions of TypeORM (including the latest Master) and am receiving the following error in Metro:

error: Error: Unable to resolve module `path` from `node_modules/typeorm/browser/platform/PlatformTools.js`: path could not be found within the project.

If you are sure the module exists, try these steps:
 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules: rm -rf node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
    at ModuleResolver.resolveDependency (/Users/mahdi/Documents/Code/PetroOutlet/supersonic/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:186:15)
    at ResolutionRequest.resolveDependency (/Users/mahdi/Documents/Code/PetroOutlet/supersonic/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:52:18)
    at DependencyGraph.resolveDependency (/Users/mahdi/Documents/Code/PetroOutlet/supersonic/node_modules/metro/src/node-haste/DependencyGraph.js:287:16)
    at Object.resolve (/Users/mahdi/Documents/Code/PetroOutlet/supersonic/node_modules/metro/src/lib/transformHelpers.js:267:42)
    at /Users/mahdi/Documents/Code/PetroOutlet/supersonic/node_modules/metro/src/DeltaBundler/traverseDependencies.js:434:31
    at Array.map (<anonymous>)
    at resolveDependencies (/Users/mahdi/Documents/Code/PetroOutlet/supersonic/node_modules/metro/src/DeltaBundler/traverseDependencies.js:431:18)
    at /Users/mahdi/Documents/Code/PetroOutlet/supersonic/node_modules/metro/src/DeltaBundler/traverseDependencies.js:275:33
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/Users/mahdi/Documents/Code/PetroOutlet/supersonic/node_modules/metro/src/DeltaBundler/traverseDependencies.js:87:24)

My current “metro.config.js”:

const blacklist = require("metro-config/src/defaults/blacklist")

module.exports = {
  transformer: {
    assetPlugins: ["expo-asset/tools/hashAssetFiles"],
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: false,
      },
    }),
  },
  resolver: {
    blacklistRE: blacklist([/typeorm\/(?!browser).*/, /typeorm$/]),
  },
}

My current “babel.config.js”:

module.exports = function (api) {
  api.cache(true)
  return {
    presets: ["babel-preset-expo"],
    plugins: [
      "@babel/transform-react-jsx-source",
      "babel-plugin-transform-typescript-metadata",
    ],
    env: {
      production: {
        plugins: ["react-native-paper/babel"],
      },
    },
  }
}

Notes:

  • I do import “reflect-metadata” early in the app (before registerRootComponent)
  • Am running Expo Bare Workflow SDK 39 (basically RN 0.63.3)
  • Have attempted TypeORM 0.2.25-28 & latest branch - all cause the same issue.
  • Is a Typescript project (3.9.2)
  • I am able to correct the issue (in a monkey patch way) and have been able to develop perfectly fine by commenting out all native module references (path, fs, etc.) & commenting out all other drivers that are not expo-sqlite when they are initially included by TypeORM
  • Based on the above, I am willing to bet this is an issue with metro pulling the wrong PlatformTools (not PlatformToolsBrowser)
  • I was able to reproduce this exact issue with this repo as a base: https://github.com/vinipachecov/react-native-typeorm-example/issues/4

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
husseinmcommented, Oct 16, 2020

Your updated configuration worked (I still reference typeorm/browser though in code).

Consider this closed, thank you!

0reactions
imnotjamescommented, Oct 11, 2020

At this point, pretty sure it’s not a typeorm issue. Let me know if you some agree and we can reopen.

If you’d like to chat about it in general including debugging etc, ping me on the community slack - cheers!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setup TypeORM with React-Native - DEV Community ‍ ‍
I've faced a great amount of trouble trying to successfully setup TypeORM with React-Native and this is my attempt to help.
Read more >
typeorm where in ids Code Example
Attempted import error: 'Map' is not exported from 'react-leaflet' (imported as 'LeafletMap'). ... Can i open native video playback for both ( ...
Read more >
What happens when `typeorm/browser/index.js` throws ...
What happens when `typeorm/browser/index.js` throws "Module parse failed: 'import' and 'export' may appear only with 'sourceType: module' ...
Read more >
expo you may need an appropriate loader to handle this file ...
If you import something in a file Babel handles, it will just find it, but Typescript will refuse unless you include the path...
Read more >
npm - Snyk
@alancnet/fantasy-names · @alexamies/chinesedict-js · @alifd/next · @alpacahq/alpaca-trade-api · @amcharts/amcharts3-angular · @amcharts/amcharts4 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found