babel / generator-babel-boilerplate

A Yeoman generator to author libraries in ES2015 (and beyond!) for Node and the browser.
MIT License
381 stars 57 forks source link

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

Open PolGuixe opened 7 years ago

PolGuixe commented 7 years ago

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?

jamesplease commented 7 years ago

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, https://github.com/airbnb/react-native-maps/commit/36a36917e4897c934b5bfe9cbaf1a63f87637e8e, 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?

PolGuixe commented 7 years ago

@jmeas I can test it. 😉

jamesplease commented 7 years ago

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

jamesplease commented 7 years ago

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?

PolGuixe commented 7 years ago

@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?

jamesplease commented 7 years ago

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.

PolGuixe commented 7 years ago

@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.