0

I'm working on a React Native project and I use Jenkins CI to generate Android production builds. My CI configuration first uses the following command to install dependencies before proceeding to generating a JS Bundle and passing that to Android Build:

npm install --production

I also recently updated my React Native version to 0.57.4 , after which I also needed to switch to the metro-react-native-babel-preset (v0.49.1). I added that to my devDependencies in package.json and also updated my .babelrc like so:

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

(as stated here: https://github.com/facebook/metro/tree/master/packages/metro-react-native-babel-preset)

Since then, the task on the CI server fails (but on my local machine its fine), saying Error: Cannot find module 'metro-react-native-babel-preset' since the preset is added to devDependencies and the --production stops npm from installing any devDependencies

(as stated here - "https://docs.npmjs.com/cli/install" - "With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies").

Should I add the preset in the dependencies, change my CI config or is there something different I should do?

Until now the default configuration, i.e:

{
  "presets": [
    "react-native"
  ],
  ...
}

worked fine, but after the React Native update, I started getting errors.

Divyansh Goenka
  • 997
  • 2
  • 12
  • 35
  • This is a common problem with npm modules. Some months ago, I has a similar problem with babel https://stackoverflow.com/questions/51686071/babel-js-file-cant-resolve-babel-runtime-helpers-builtin-classcallcheck Also, this is not a jenkins question – JRichardsz Nov 13 '18 at 14:03
  • is this dependency metro-react-native-babel-preset required to perform the common command for production : npm run build ?? What commands are you executing for production environment? – JRichardsz Nov 13 '18 at 14:16
  • This dependency is a babel preset, which means it does some important transpiling. Therefore it definitely needs to run even in a production build (though it needn't be a part of the output bundle) – Divyansh Goenka Nov 14 '18 at 04:40
  • So, if this dependency is required to build, it must be in dependencies sections but is in devDependencies. Is this correct? Also, how is added this dependency? npm install -i .... – JRichardsz Nov 14 '18 at 14:02
  • As a general practice, babel presets are kept in devDependencies , and so it was added using `npm install --save-dev ` – Divyansh Goenka Nov 15 '18 at 15:04
  • But, when you run your production commands you have an error because this dependency is in devDependencies section and must be in dependencies sections. Is this ok? – JRichardsz Nov 15 '18 at 15:35
  • I finally solved the issue by removing the flag – Divyansh Goenka Nov 16 '18 at 17:03

1 Answers1

0

I solved it by removing the --production flag

Divyansh Goenka
  • 997
  • 2
  • 12
  • 35