react-native-obfuscating-transformer icon indicating copy to clipboard operation
react-native-obfuscating-transformer copied to clipboard

TypeError: Cannot read property 'transformFile' of undefined

Open ExoMemphiz opened this issue 5 years ago • 7 comments

Versions:

"react-native": "0.59.10", "react-native-obfuscating-transformer": "^1.0.0",

Files:

metro.config.js:

module.exports = {
    transformer: {
        babelTransformerPath: require.resolve("./transformer"),
        getTransformOptions: async () => ({
            transform: {
                experimentalImportSupport: false,
                inlineRequires: false,
            },
        }),
    },
};

transformer.js:

const obfuscatingTransformer = require('react-native-obfuscating-transformer')

module.exports = obfuscatingTransformer({})

Error I am getting:

Loading dependency graph, done.
Loading dependency graph...error Cannot read property 'transformFile' of undefined
debug TypeError: Cannot read property 'transformFile' of undefined
    at /home/chris/Documents/JSObfuscation/ObfuscationTest/node_modules/metro/src/Bundler.js:83:34
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/home/chris/Documents/JSObfuscation/ObfuscationTest/node_modules/metro/src/Bundler.js:14:24)
    at _next (/home/chris/Documents/JSObfuscation/ObfuscationTest/node_modules/metro/src/Bundler.js:34:9)

Repo

Simplest repo I could make that reproduces this error:

https://github.com/ExoMemphiz/ObfuscationTest/

ExoMemphiz avatar Sep 26 '19 12:09 ExoMemphiz

Alright, I got slightly further with a different repo that I found that used this library.

I needed to add these lines of code to the getMetroTransformer.js file:

const metroVersion = semver(require('metro/package.json').version).minor;
if (metroVersion >= 51) {
  return require('metro-react-native-babel-transformer/src/index');
}

And of course have the metro-react-native-babel-transformer installed, as well as having this .babelrc file:

{
  "presets": ["module:metro-react-native-babel-preset"]
}

It seems to work (Tried react-native v0.59.10 and v0.61.1 currently), but minification happens on the bundle, after obfuscating, which I think is the reason that the output is basically the same, if I obfuscate or not.

Btw. these are the dependencies:

  "dependencies": {
    "react": "16.8.3",
    "react-native": "0.61.1"
  },
  "devDependencies": {
    "babel-core": "6.26.0",
    "metro-react-native-babel-preset": "0.56.0",
    "react-native-obfuscating-transformer": "^1.0.0-rc.0"
  }

I get this in the log when I run the ./gradlew assembleRelease

> Task :app:bundleReleaseJsAndAssets
warning: the transform cache was reset.
Loading dependency graph, done.
transform[stdout]: src/App.js
transform[stdout]: Obfuscating src/App.js
info Writing bundle output to:, .../index.android.bundle
info Done writing bundle output

Which should mean it actually obfuscates the code, unfortunately it is not shown in the output bundle itself. Also the selfDefending option breaks the app, I assume because of the above reason - minifying the output changes the code, and thus breaks the selfDefending code.

Any way to keep the obfuscated code, while bundling it?

ExoMemphiz avatar Sep 27 '19 08:09 ExoMemphiz

I have the same issue, did you managed to solve it?

mrcarjul avatar Feb 07 '20 22:02 mrcarjul

same here

jamal-rahimzadegan avatar May 12 '20 06:05 jamal-rahimzadegan

Can every one give me the solution?

anhdevit avatar May 14 '20 08:05 anhdevit

I find the solution when using with react-native 0.61 This is my metro.config.js My problem disappear when I change babelTransformerPath: require.resolve("./transformer") to getTransformModulePath: () => { return require.resolve('./transformer'); },

module.exports = {
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: false,
      },
    }),
    getTransformModulePath: () => {
      return require.resolve('./transformer');
    },
  },
};

anhdevit avatar May 14 '20 08:05 anhdevit

I find the solution when using with react-native 0.61 This is my metro.config.js My problem disappear when I change babelTransformerPath: require.resolve("./transformer") to getTransformModulePath: () => { return require.resolve('./transformer'); },

module.exports = {
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: false,
      },
    }),
    getTransformModulePath: () => {
      return require.resolve('./transformer');
    },
  },
};

yes this issue has been resolved from this Solution. thanks a lot man.

mahsanfarooq avatar Jun 18 '20 07:06 mahsanfarooq

npm i babylon --save-dev

timorss avatar Dec 08 '21 07:12 timorss