facebook / metro

🚇 The JavaScript bundler for React Native
https://metrobundler.dev
MIT License
5.24k stars 626 forks source link

Right-hand side of 'instanceof' is not an object / FailedToResolveUnsupportedError #1393

Open aldebout opened 2 days ago

aldebout commented 2 days ago

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

What is the current behavior? When adding unstable_enablePackageExports = true to config and starting the dev server with expo dev, the app crashes and it looks like there's an issue with error reporting inside of metro.

iOS Bundling failed 1871ms node_modules/expo-router/entry.js (4294 modules)
 ERROR  TypeError: Right-hand side of 'instanceof' is not an object
    at ModuleResolver.resolveDependency (/project-path/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:130:24)
    at DependencyGraph.resolveDependency (/project-path/node_modules/metro/src/node-haste/DependencyGraph.js:235:43)
image

If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test.

Not sure how to repro since I think there's an underlying issue with my repo but this is about the failure to properly throw the error.

What is the expected behavior?

I get a useful error.

Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.

node: 20.16.0 pnpm: 9.6.0 os: macos Sonoma 14.7 metro: 0.81.0 expo: 52.0.7 RN: 0.76.2

Project is in a pnpm + turborepo monorepo.

Full metro config:

let config ={
  resolver: {
    assetExts: [
      'bmp',  'gif',  'jpg',  'jpeg',
      'png',  'psd',  'svg',  'webp',
      'xml',  'm4v',  'mov',  'mp4',
      'mpeg', 'mpg',  'webm', 'aac',
      'aiff', 'caf',  'm4a',  'mp3',
      'wav',  'html', 'pdf',  'yaml',
      'yml',  'otf',  'ttf',  'zip',
      'heic', 'avif', 'db'
    ],
    assetResolutions: [ '1', '1.5', '2', '3', '4' ],
    platforms: [ 'ios', 'android' ],
    sourceExts: [
      'ts',  'tsx',  'mjs',
      'js',  'jsx',  'json',
      'cjs', 'scss', 'sass',
      'css', 'css'
    ],
    blockList: /(\/__tests__\/.*)$/,
    dependencyExtractor: undefined,
    disableHierarchicalLookup: false,
    emptyModulePath: '/project-path/node_modules/metro-runtime/src/modules/empty-module.js',
    enableGlobalPackages: false,
    extraNodeModules: {},
    hasteImplModulePath: undefined,
    nodeModulesPaths: [
      '/project-path/apps/expo/node_modules',
      '/project-path/node_modules'
    ],
    resolveRequest: [Function: resolveRequest],
    resolverMainFields: [ 'react-native', 'browser', 'main' ],
    unstable_conditionNames: [ 'require', 'import' ],
    unstable_conditionsByPlatform: { ios: [Array], android: [Array], web: [Array] },
    unstable_enablePackageExports: true,
    useWatchman: true,
    requireCycleIgnorePatterns: [ /(^|\/|\\)node_modules($|\/|\\)/ ]
  },
  serializer: {
    polyfillModuleNames: [],
    getRunModuleStatement: [Function: getRunModuleStatement],
    getPolyfills: [Function: getPolyfills],
    getModulesRunBeforeMainModule: [Function: getModulesRunBeforeMainModule],
    processModuleFilter: [Function: processModuleFilter],
    createModuleIdFactory: [Function: createNumericModuleIdFactory],
    experimentalSerializerHook: [Function: experimentalSerializerHook],
    customSerializer: [AsyncFunction (anonymous)],
    isThirdPartyModule: [Function: isThirdPartyModule]
  },
  server: {
    enhanceMiddleware: [Function: enhanceMiddleware],
    forwardClientLogs: true,
    port: 8081,
    rewriteRequestUrl: [Function: rewriteExpoRequestUrl],
    unstable_serverRoot: '/project-path',
    useGlobalHotkey: true,
    verifyConnections: false
  },
  symbolicator: {
    customizeFrame: [Function: customizeFrame],
    customizeStack: [AsyncFunction: customizeStack]
  },
  transformer: {
    assetPlugins: [ 'expo-asset/tools/hashAssetFiles' ],
    asyncRequireModulePath: '/project-path/node_modules/metro-runtime/src/modules/asyncRequire.js',
    assetRegistryPath: '@react-native/assets-registry/registry',
    babelTransformerPath: '/project-path/node_modules/@expo/metro-config/build/babel-transformer.js',
    dynamicDepsInPackages: 'throwAtRuntime',
    enableBabelRCLookup: true,
    enableBabelRuntime: true,
    getTransformOptions: [AsyncFunction: getTransformOptions],
    globalPrefix: '',
    hermesParser: false,
    minifierConfig: {
      mangle: [Object],
      output: [Object],
      sourceMap: [Object],
      toplevel: false,
      compress: [Object]
    },
    minifierPath: 'metro-minify-terser',
    optimizationSizeLimit: 153600,
    transformVariants: { default: {} },
    workerPath: 'metro/src/DeltaBundler/Worker',
    publicPath: '/assets',
    allowOptionalDependencies: true,
    unstable_allowRequireContext: true,
    unstable_dependencyMapReservedName: null,
    unstable_disableModuleWrapping: false,
    unstable_disableNormalizePseudoGlobals: false,
    unstable_renameRequire: false,
    unstable_compactOutput: false,
    unstable_memoizeInlineRequires: false,
    unstable_workerThreads: false,
    postcssHash: null,
    browserslistHash: null,
    sassVersion: '1.81.0',
    reanimatedVersion: '3.16.1',
    _expoRelativeProjectRoot: 'apps/expo',
    cssInterop_transformerPath: '/project-path/node_modules/@expo/metro-config/build/transform-worker/transform-worker.js',
    cssInterop_outputDirectory: '../../node_modules/react-native-css-interop/.cache'
  },
  watcher: {
    additionalExts: [ 'env.development.local', 'env.local', 'env.development', 'env' ],
    healthCheck: {
      enabled: false,
      filePrefix: '.metro-health-check',
      interval: 30000,
      timeout: 5000
    },
    unstable_workerThreads: false,
    watchman: { deferStates: [Array] }
  },
  cacheStores: [
    FileStore {
      _root: '/project-path/apps/expo/node_modules/.cache/metro'
    }
  ],
  cacheVersion: '1.0',
  projectRoot: '/project-path/apps/expo',
  stickyWorkers: true,
  watchFolders: [
    '/project-path/node_modules',
    '/project-path/apps/nextjs',
    '/project-path/apps/expo',
    '/project-path/packages/workflows',
    '/project-path/packages/validators',
    '/project-path/packages/utils',
    '/project-path/packages/ui',
    '/project-path/packages/stripe',
    '/project-path/packages/scripts',
    '/project-path/packages/db',
    '/project-path/packages/brevo-client',
    '/project-path/packages/api',
    '/project-path/tooling/typescript',
    '/project-path/tooling/tailwind',
    '/project-path/tooling/prettier',
    '/project-path/tooling/github',
    '/project-path/tooling/eslint'
  ],
  transformerPath: '/project-path/node_modules/react-native-css-interop/dist/metro/transformer.js',
  maxWorkers: 6,
  resetCache: false,
  unstable_perfLoggerFactory: [Function (anonymous)]
}