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

Unable to use without babel-preset-es2015 #11

Closed
vkbansal opened this issue Jul 4, 2017 · 12 comments
Closed

Unable to use without babel-preset-es2015 #11

vkbansal opened this issue Jul 4, 2017 · 12 comments

Comments

@vkbansal
Copy link

vkbansal commented Jul 4, 2017

Getting the following error

Error: Couldn't find preset "es2015" relative to directory "/Users/<username>/Projects/<project-name>/node_modules/shallowequal"

I'm using babel-preset-env and not es2015

@dashed
Copy link
Owner

dashed commented Jul 4, 2017

Hey, @vkbansal , can I get some more information on how you're using shallowequal? is it in webpack?

@vkbansal
Copy link
Author

vkbansal commented Jul 4, 2017

Yes, I'm using webpack.

My build worked when I deleted babel key from package.json

@dashed
Copy link
Owner

dashed commented Jul 4, 2017

@vkbansal I'm unable to re-produce this issue...

I tried to create a quick app using create-react-app and added shallowequal as a dependency. And ran yarn start without issues.

@vkbansal
Copy link
Author

vkbansal commented Jul 4, 2017

I'll try to create an reproducible project and update you

@dashed
Copy link
Owner

dashed commented Jul 4, 2017

Thanks that'd be helpful 👍

I'm genuinely interested to see if my babel config is incorrect (or needs fixing) since it's only meant for tests.

@vkbansal
Copy link
Author

vkbansal commented Jul 4, 2017

Here you go: https://github.com/vkbansal/se-test

  • Clone it and cd
  • run npm install and npm start.

@dashed
Copy link
Owner

dashed commented Jul 4, 2017

@vkbansal so I did some investigating. It appears you would need to do the following changes in your webpack (i.e. change from 'node_modules' to /node_modules/ in exclude):

diff --git a/webpack.config.js b/webpack.config.js
index 0a862b1..b6f59dd 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -24,6 +24,7 @@ let config = {
                 use: [{
                     loader: 'babel-loader',
                     options: {
+                        // babelrc: false,
                         presets: [
                             ['env', {
                                 targets: {
@@ -35,7 +36,7 @@ let config = {
                     }
                 }],
                 exclude: [
-                    'node_modules'
+                    /node_modules/
                 ]
             }
         ]

I haven't used string-based conditions before in webpack (only regex ones): https://webpack.js.org/configuration/module/#condition https://webpack.js.org/configuration/module/#rule-exclude

I also tried babelrc: false; which works.

In addition, I tried whitelist approach (only include the src directory); which also works: https://webpack.js.org/configuration/module/#rule-include

@vkbansal
Copy link
Author

vkbansal commented Jul 4, 2017

Thanks. I learnt something new today.

@vkbansal vkbansal closed this as completed Jul 4, 2017
@cooperka
Copy link
Contributor

I also get this issue using shallowequal v1.0.1 with React Native. The React Native packager tries to consume all babel configs by default, and unfortunately it can't be turned off (as suggested above with webpack). If you were to use a .babelrc file (without publishing it), that would resolve this issue. I'll try to make a PR soon!

cooperka added a commit to cribspot/shallowequal that referenced this issue Jul 10, 2017
And ignore it when publishing. Fixes dashed#11.
@dashed
Copy link
Owner

dashed commented Jul 10, 2017

@cooperka oh interesting!

I'll go ahead and merge your PR and cut a release soon.

@dashed
Copy link
Owner

dashed commented Jul 10, 2017

@cooperka I've released shallowequal with your PR at v1.0.2.

@cooperka
Copy link
Contributor

So quick! Thanks a lot @dashed.

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

3 participants