Skip to content

What should be the right metro.config.js for PNPM monorepo? #1016

Description

@shawnthye-guru

Do you want to request a feature or report a bug?
Bug report

What is the current behavior?
Trying out the latest react-native 0.72 on the experiment symlink support with pnpm workspace

Having the folder setup as below

root/packages/*
root/example/package.json
root/example/metro.config.js
root/package.json
root/pnpm-workspace.yaml

Base on the doc found in metro https://facebook.github.io/metro/docs/configuration#projectroot
image

This doesn't work

constconfig={projectRoot: path.resolve(__dirname,'..'),resolver: {unstable_enableSymlinks: true,unstable_enablePackageExports: true,},};module.exports=mergeConfig(getDefaultConfig(__dirname),config);

And getting the error below:

Error: Unable to resolve module ./index from /Users/shawnthye/workspaces/guru/mobile-packages/.: None of these files exist:
* index(.native|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
* index/index(.native|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
at ModuleResolver.resolveDependency (/Users/shawnthye/workspaces/guru/mobile-packages/node_modules/.pnpm/metro@0.76.7/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:114:15)
at DependencyGraph.resolveDependency (/Users/shawnthye/workspaces/guru/mobile-packages/node_modules/.pnpm/metro@0.76.7/node_modules/metro/src/node-haste/DependencyGraph.js:277:43)
at /Users/shawnthye/workspaces/guru/mobile-packages/node_modules/.pnpm/metro@0.76.7/node_modules/metro/src/lib/transformHelpers.js:169:21
at Server._resolveRelativePath (/Users/shawnthye/workspaces/guru/mobile-packages/node_modules/.pnpm/metro@0.76.7/node_modules/metro/src/Server.js:1045:12)
at async Server.requestProcessor [as _processBundleRequest] (/Users/shawnthye/workspaces/guru/mobile-packages/node_modules/.pnpm/metro@0.76.7/node_modules/metro/src/Server.js:449:37)
at async Server._processRequest (/Users/shawnthye/workspaces/guru/mobile-packages/node_modules/.pnpm/metro@0.76.7/node_modules/metro/src/Server.js:383:7)

But this will work

constconfig={watchFolders: [path.resolve(__dirname,'..')],resolver: {unstable_enableSymlinks: true,unstable_enablePackageExports: true,},};module.exports=mergeConfig(getDefaultConfig(__dirname),config);

What should be the right config for monorepo setup? is this a bug or is something I have done wrongly?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions