babel/generator-babel-boilerplate

Error: Couldn't find preset "latest" relative to directory

Opened this issue · 7 comments

I am trying to use a package I've created -https://github.com/Zetoff/zetoff-js-helpers-, however when installing it in a project.

I am getting this error:

error: bundling: Error: Couldn't find preset "latest" relative to directory "{pathToTheProject}/ReactNativeApp/node_modules/zetoff-js-helpers"

Any idea why it's happening?

I'm not certain, since I don't use React Native myself, but I've heard that there are some issues with .babelrc being in the repo for React Native projects. This commit, react-native-maps/react-native-maps@36a3691, demonstrates what seems to be a fix.

I'll update this and do a release tonight. @PolGuixe , I'll ping you when that's done, then you can do a test? How's that sound?

@jmeas I can test it. 😉

Didn't have time to do this tonight, but i will first this tomorrow AM! Sorry for the delay @PolGuixe

Hmmm, you know what, I was being silly – most folks will want the .babelrc file. Most projects can get away with removing the .babelrc file because they're nested deps within the node_modules directory, but this outputs your project's structure.

I'm not sure how React Native usually works – I guess it has its own compiler that either is not Babel, or uses Babel under the hood?

Perhaps it'd be better to just add a note in the README letting folks know that to use this with React Native, you'll need to delete the generated .babelrc file? Or perhaps there should be a -react-native flag that would not output those files?

@jmeas I don't understand. Is the .babelrc not required? I would like to use this package in different Js frameworks, not just React-Native.

Sorry, I don't really understand the fix... Basically is ignoring the .babelrc from the npm distribution, so it doesn't gets bundled in the package? What the consequences of ignoring the .babelrc file?

Is the .babelrc not required?

@PolGuixe , .babelrc is required for all projects that use Babel to compile their JavaScript. This includes all non-React Native projects, since those projects rely on Babel to work in browsers. .babelrc is the configuration file for Babel, so it tells Babel what to do.

From what I'm seeing in other OS projects, it is possible that React Native does not use Babel to compile the JavaScript, and, in fact, explodes if a .babelrc is present (for some reason that I don't understand).

Basically is ignoring the .babelrc from the npm distribution, so it doesn't gets bundled in the package?

Yes, this is the fix, as I understand it, for React Native projects only. But this would break non-React Native projects, because they must be compiled by Babel, and consequently, need a .babelrc to configure Babel.

What the consequences of ignoring the .babelrc file?

Ignoring .babelrc means that Babel will not be configured to do anything. This would break non React Native projects, but it seems to be a requirement for React Native projects, likely because they don't use Babel to compile the JS.

I've never used React Native, so my knowledge of .babelrc causing issues for those sorts of projects come from seeing other OSS projects dealing with it.

Does that make sense? 🤔


The tl;dr fix for React Native projects right now would be:

  1. use the boilerplate as usual
  2. delete the .babelrc file that is generated for you

and that should work, based on what I've read in other issues. But, again, since I don't use React Native, nor know much about it, I'm making an educated guess here.

@jmeas many thanks for the clarification.

I'll keep investigating. I would like to use the package on both: react-native and non react-native.