javascript-obfuscator / react-native-obfuscating-transformer

Obfuscation for React Native bundles
MIT License
196 stars 100 forks source link

Missing "babylon" and other dependencies? #24

Open slhck opened 4 years ago

slhck commented 4 years ago

I am using this in a RN 0.61.5 project, and I've installed the project with:

npm install react-native-obfuscating-transformer --save-dev

When running npx react-native start, I get this error:

Loading dependency graph...Failed to construct transformer:  Error: Cannot find module 'babylon'
Require stack:
-/node_modules/react-native-obfuscating-transformer/dist/getMetroTransformer.js
-/node_modules/react-native-obfuscating-transformer/dist/obfuscatingTransformer.js
-/node_modules/react-native-obfuscating-transformer/dist/index.js
-/transformer.js
-/node_modules/metro/src/JSTransformer/worker.js
-/node_modules/metro/src/DeltaBundler/Transformer/getTransformCacheKey.js
-/node_modules/metro/src/DeltaBundler/Transformer.js
-/node_modules/metro/src/Bundler.js
-/node_modules/metro/src/IncrementalBundler.js
-/node_modules/metro/src/index.js
-/node_modules/react-native/node_modules/@react-native-community/cli/build/tools/loadMetroConfig.js
-/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/server/runServer.js
-/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/server/server.js
-/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/index.js
-/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js
-/node_modules/react-native/cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:973:15)
    at Function.Module._load (internal/modules/cjs/loader.js:855:27)
    at Module.require (internal/modules/cjs/loader.js:1033:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/node_modules/react-native-obfuscating-transformer/dist/getMetroTransformer.js:6:15)
    at Module._compile (internal/modules/cjs/loader.js:1144:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1164:10)
    at Module.load (internal/modules/cjs/loader.js:993:32)
    at Function.Module._load (internal/modules/cjs/loader.js:892:14)
    at Module.require (internal/modules/cjs/loader.js:1033:19)

After running npm i babylon --save-dev, I get:

Loading dependency graph...Failed to construct transformer:  Error: Cannot find module 'babel-traverse'
Require stack:
- /node_modules/react-native-obfuscating-transformer/dist/getMetroTransformer.js
- /node_modules/react-native-obfuscating-transformer/dist/obfuscatingTransformer.js
- /node_modules/react-native-obfuscating-transformer/dist/index.js
- /transformer.js
- /node_modules/metro/src/JSTransformer/worker.js
- /node_modules/metro/src/DeltaBundler/Transformer/getTransformCacheKey.js
- /node_modules/metro/src/DeltaBundler/Transformer.js
- /node_modules/metro/src/Bundler.js
- /node_modules/metro/src/IncrementalBundler.js
- /node_modules/metro/src/index.js
- /node_modules/react-native/node_modules/@react-native-community/cli/build/tools/loadMetroConfig.js
- /node_modules/react-native/node_modules/@react-native-community/cli/build/commands/server/runServer.js
- /node_modules/react-native/node_modules/@react-native-community/cli/build/commands/server/server.js
- /node_modules/react-native/node_modules/@react-native-community/cli/build/commands/index.js
- /node_modules/react-native/node_modules/@react-native-community/cli/build/index.js
- /node_modules/react-native/cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:973:15)
    at Function.Module._load (internal/modules/cjs/loader.js:855:27)
    at Module.require (internal/modules/cjs/loader.js:1033:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/node_modules/react-native-obfuscating-transformer/dist/getMetroTransformer.js:7:24)
    at Module._compile (internal/modules/cjs/loader.js:1144:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1164:10)
    at Module.load (internal/modules/cjs/loader.js:993:32)
    at Function.Module._load (internal/modules/cjs/loader.js:892:14)
    at Module.require (internal/modules/cjs/loader.js:1033:19)

My transformer.js is:

const obfuscatingTransformer = require("react-native-obfuscating-transformer");

module.exports = obfuscatingTransformer({
  /* options */
});

And my Metro Config:

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

I see that Babylon is part of the dependencies: https://github.com/javascript-obfuscator/react-native-obfuscating-transformer/blob/master/package.json#L14 – but then again, there seem to be duplicates?

Raymond-Cox commented 4 years ago

Same issue here, same exact setup. Will continue digging and report back if I find anything.

EDIT: Try changing metro.config.js to the following:

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

@slhck @Raymond-Cox any solution to this?

mrcarjul commented 4 years ago

add babylon and babel-traverse as dev dependencies.

razorabhu1995 commented 4 years ago

@mrcarjul After adding the dependencies, the above error is solved!!

But i get this:

Loading dependency graph, done. Loading dependency graph...Failed to construct transformer: { Error: Cannot find module 'metro/src/reactNativeTransformer' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15) at Function.Module._load (internal/modules/cjs/loader.js:562:25) at Module.require (internal/modules/cjs/loader.js:692:17) at require (internal/modules/cjs/helpers.js:25:18) at Object.getMetroTransformer (/home/naya/Documents/sabdakos/node_modules/react-native-obfuscating-transformer/dist/getMetroTransformer.js:19:16) at obfuscatingTransformer (/home/naya/Documents/sabdakos/node_modules/react-native-obfuscating-transformer/dist/obfuscatingTransformer.js:38:208) at Object. (/home/naya/Documents/sabdakos/transformer.js:3:18) at Module._compile (internal/modules/cjs/loader.js:778:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) at Module.load (internal/modules/cjs/loader.js:653:32) code: 'MODULE_NOT_FOUND' } error Cannot read property 'transformFile' of undefined. Run CLI with --verbose flag for more details. TypeError: Cannot read property 'transformFile' of undefined at /home/naya/Documents/sabdakos/node_modules/metro/src/Bundler.js:87:34 at Generator.next () at asyncGeneratorStep (/home/naya/Documents/sabdakos/node_modules/metro/src/Bundler.js:14:24) at _next (/home/naya/Documents/sabdakos/node_modules/metro/src/Bundler.js:34:9)

Any solution to this?

Raymond-Cox commented 4 years ago

@slhck @Raymond-Cox any solution to this?

What happened when you changed metro.config.js file to what I suggested?

mrcarjul commented 4 years ago

@razorabhu1995

module.exports = obfuscatingTransformer({ / add this to your transformer.js file i think it will fix it / upstreamTransformer: require('metro-react-native-babel-transformer'),

byteab commented 4 years ago

@Raymond-Cox with your solution error is gone but nothing happened to source code it's not encrypted.

byteab commented 4 years ago

I think the contributors of this library must have a re iterate over how metro bundler work in react native >= 0.60

AustinZuniga commented 4 years ago

+1

AustinZuniga commented 4 years ago

Solved:

https://github.com/javascript-obfuscator/react-native-obfuscating-transformer/issues/2#issuecomment-595575844

byteab commented 4 years ago

@AustinZuniga tnx that solved the problem

dooleyb1 commented 4 years ago

@mrcarjul After adding the dependencies, the above error is solved!!

But i get this:

Loading dependency graph, done. Loading dependency graph...Failed to construct transformer: { Error: Cannot find module 'metro/src/reactNativeTransformer' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15) at Function.Module._load (internal/modules/cjs/loader.js:562:25) at Module.require (internal/modules/cjs/loader.js:692:17) at require (internal/modules/cjs/helpers.js:25:18) at Object.getMetroTransformer (/home/naya/Documents/sabdakos/node_modules/react-native-obfuscating-transformer/dist/getMetroTransformer.js:19:16) at obfuscatingTransformer (/home/naya/Documents/sabdakos/node_modules/react-native-obfuscating-transformer/dist/obfuscatingTransformer.js:38:208) at Object. (/home/naya/Documents/sabdakos/transformer.js:3:18) at Module._compile (internal/modules/cjs/loader.js:778:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) at Module.load (internal/modules/cjs/loader.js:653:32) code: 'MODULE_NOT_FOUND' } error Cannot read property 'transformFile' of undefined. Run CLI with --verbose flag for more details. TypeError: Cannot read property 'transformFile' of undefined at /home/naya/Documents/sabdakos/node_modules/metro/src/Bundler.js:87:34 at Generator.next () at asyncGeneratorStep (/home/naya/Documents/sabdakos/node_modules/metro/src/Bundler.js:14:24) at _next (/home/naya/Documents/sabdakos/node_modules/metro/src/Bundler.js:34:9)

Any solution to this?

@razorabhu1995 Did you manage to resolve this issue? I too am getting the error Error: Cannot find module 'metro/src/reactNativeTransformer'

dooleyb1 commented 4 years ago

@razorabhu1995 so the fix for this has actually already been merged into master, however it has not been deployed to npm. I manually implemented the changes within node_modules - see https://github.com/javascript-obfuscator/react-native-obfuscating-transformer/pull/15.

anhdevit commented 4 years ago

yarn add babylon -dev