facebook / metro

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

Error: Option 'mapper' isn't supported by the Node crawler #418

Open vicki15 opened 5 years ago

vicki15 commented 5 years ago

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

Repro steps I'm running Metro.runBuild() and getting the error Loading dependency graph...Failed to construct transformer: Error: Option 'mapper' isn't supported by the Node crawler at nodeCrawl (/****/node_modules/metro/node_modules/jest-haste-map/build/crawlers/node.js:227:11) at HasteMap._crawl (/***/node_modules/metro/node_modules/jest-haste-map/build/index.js:1021:14) at /***/node_modules/metro/node_modules/jest-haste-map/build/index.js:572:21

Note: this only repro's with watchman disabled.

resolver: { useWatchman: false }

What is the expected behavior? No errors when bundling ;)

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

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

module.exports = {
    resolver: {
        useWatchman: false,
        blacklistRE: blacklist([
            /node_modules\/.*\/node_modules\/react-native\/.*/,
            /build\/private\/tmp\/.*/,
        ]),
        extraNodeModules: {
          "react-native": path.resolve("node_modules/react-native"),
          "@babel/runtime": path.resolve("node_modules/@babel/runtime"),

        },
        hasteImplModulePath: path.resolve('node_modules/react-native/jest/hasteImpl.js'),
    },
    transformer: {
        babelTransformerPath: path.resolve('node_modules/metro-react-native-babel-transformer/src/index'),
        assetRegistryPath: path.resolve('node_modules/react-native/Libraries/Image/AssetRegistry'),
    },
    serializer: {
        getModulesRunBeforeMainModule: () => [
            path.resolve('node_modules/react-native/Libraries/Core/InitializeCore.js')
        ],
        getPolyfills: require(path.resolve('node_modules/react-native/rn-get-polyfills')),
    },
    resetCache: true
};

metro version "metro": "0.54.0"

How to fix Note: This is caused by a bug in jest-haste-map that was fixed 2 days ago, so metro needs to update their dependency to the latest version of jest-haste-map - where they no longer throw this error and simply ignore the config option. This should fix the error! Otherwise - I am not sure where the 'mapper' option is being passed through, I assume this is somewhere in the metro code and should be removed. https://github.com/facebook/jest/pull/8558

mikehardy commented 5 years ago

Until jest (or jest-haste-map) does a release that is integrated here you can use this (without the .txt extension I needed for github) in combination with patch-package to move forward jest-haste-map+24.8.0.patch.txt

alfonsojbro commented 4 years ago

Have you found a better answer? I have been struggling with this problem for days now and have not been able to solve it.

mikehardy commented 4 years ago

I don't believe current versions of anything have this problem. I'd forgotten about it and no longer have the patch integrated. I'm on react-native 0.61.x now, so I think the answer is patch until you get current.