Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'transformFile' of undefined #16

Open
ExoMemphiz opened this issue Sep 26, 2019 · 7 comments
Open

TypeError: Cannot read property 'transformFile' of undefined #16

ExoMemphiz opened this issue Sep 26, 2019 · 7 comments

Comments

@ExoMemphiz
Copy link

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
Copy link
Author

ExoMemphiz commented Sep 27, 2019

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?

@mrcarjul
Copy link

mrcarjul commented Feb 7, 2020

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

@jamal-rahimzadegan
Copy link

same here

@anhdevit
Copy link

Can every one give me the solution?

@anhdevit
Copy link

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');
    },
  },
};

@mahsanfarooq
Copy link

mahsanfarooq commented Jun 18, 2020

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.

@timorss
Copy link

timorss commented Dec 8, 2021

npm i babylon --save-dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants