Skip to content

Question about metro and monorepo #212

Description

@malopezr7

Describe the bug
I feel this is not related to the library but I am having a problem using it in my repository as well, I want metro to work with pnpm but when I import react-native-monorepo-tools all the time I get a package.json not found in path error.

I am currently using rush as my monorepo manager and these are my files:

metro.config.json:

const exclusionList = require('metro-config/src/defaults/exclusionList');  
const {  
  getMetroTools,  
  getMetroAndroidAssetsResolutionFix,  
} = require('react-native-monorepo-tools');  
  
const monorepoMetroTools = getMetroTools();  
  
const androidAssetsResolutionFix = getMetroAndroidAssetsResolutionFix();  
  
module.exports = {  
  transformer: {  
    // Apply the Android assets resolution fix to the public path...  
    publicPath: androidAssetsResolutionFix.publicPath,  
    getTransformOptions: async () => ({  
    transform: {  
    experimentalImportSupport: false,  
    inlineRequires: false,  
  },  
  }),  
  },  
  server: {  
    // ...and to the server middleware.  
    enhanceMiddleware: (middleware) => {  
    return androidAssetsResolutionFix.applyMiddleware(middleware);  
    },  
  },  
  // Add additional Yarn workspace package roots to the module map.  
 // This allows importing importing from all the project's packages.  watchFolders: monorepoMetroTools.watchFolders,  
  resolver: {  
    // Ensure we resolve nohoist libraries from this directory.  
    blockList: exclusionList(monorepoMetroTools.blockList),  
    extraNodeModules: monorepoMetroTools.extraNodeModules,  
  },  
};

package.json:

{
  "name": "@mlopez/mobile",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "@mlopez/ui": "workspace:*",
    "react": "18.2.0",
    "react-native": "0.71.7",
    "styled-components": "5.3.10",
    "find-root": "1.1.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native-community/eslint-config": "^3.2.0",
    "@react-native-community/cli-platform-ios": "11.2.0",
    "@rnx-kit/metro-config": "1.3.6",
    "@tsconfig/react-native": "^2.0.2",
    "@types/jest": "^29.2.1",
    "@types/react": "^18.0.24",
    "@types/react-test-renderer": "^18.0.0",
    "@types/styled-components-react-native": "5.2.1",
    "@rnx-kit/metro-resolver-symlinks": "0.1.28",
    "babel-jest": "^29.2.1",
    "eslint": "^8.19.0",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.73.9",
    "prettier": "^2.4.1",
    "react-test-renderer": "18.2.0",
    "@rnx-kit/babel-preset-metro-react-native": "1.1.4",
    "typescript": "4.8.4",
    "react-native-monorepo-tools": "1.2.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

error:

yarn run v1.22.19
$ react-native start --reset-cache
error package.json not found in path.
Error: package.json not found in path
    at findRoot (/Users/mlopezr-local/Codes/scrm-mono-test/common/temp/node_modules/.pnpm/find-root@1.1.0/node_modules/find-root/index.js:19:11)
    at findRoot (/Users/mlopezr-local/Codes/scrm-mono-test/common/temp/node_modules/.pnpm/find-root@1.1.0/node_modules/find-root/index.js:28:10)
    at findRoot (/Users/mlopezr-local/Codes/scrm-mono-test/common/temp/node_modules/.pnpm/find-root@1.1.0/node_modules/find-root/index.js:28:10)
    at findRoot (/Users/mlopezr-local/Codes/scrm-mono-test/common/temp/node_modules/.pnpm/find-root@1.1.0/node_modules/find-root/index.js:28:10)
    at findRoot (/Users/mlopezr-local/Codes/scrm-mono-test/common/temp/node_modules/.pnpm/find-root@1.1.0/node_modules/find-root/index.js:28:10)
    at findRoot (/Users/mlopezr-local/Codes/scrm-mono-test/common/temp/node_modules/.pnpm/find-root@1.1.0/node_modules/find-root/index.js:28:10)
    at findRoot (/Users/mlopezr-local/Codes/scrm-mono-test/common/temp/node_modules/.pnpm/find-root@1.1.0/node_modules/find-root/index.js:28:10)
    at findRoot (/Users/mlopezr-local/Codes/scrm-mono-test/common/temp/node_modules/.pnpm/find-root@1.1.0/node_modules/find-root/index.js:28:10)
    at findRoot (/Users/mlopezr-local/Codes/scrm-mono-test/common/temp/node_modules/.pnpm/find-root@1.1.0/node_modules/find-root/index.js:28:10)
    at getMonorepoRoot (/Users/mlopezr-local/Codes/scrm-mono-test/common/temp/node_modules/.pnpm/react-native-monorepo-tools@1.2.1/node_modules/react-native-monorepo-tools/src/get-monorepo-root.js:13:16)
info Run CLI with --verbose flag for more details.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this  #command.

have you ever had the same error?

if thereis some problem with this issue please delete, 0 problems

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationImprovements or additions to documentation

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions