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

TypeError Object.values is not a function #37

Closed
bcowgill opened this Issue Jun 16, 2016 · 5 comments

Comments

Projects
None yet
3 participants
@bcowgill
Copy link

bcowgill commented Jun 16, 2016

Perhaps this is just a configuration issue, but when I try to use this preset to transpile a call to Object.values so I can use it in the browser I get Object.values is not a function.

Looks like it's not installing a shim.

my original .babelrc was
{ "presets": ["react", "es2015", "stage-2"] }

.babelrc: settings I tried:
{ "presets": ["react", "es2017"] } // causes me test failures in node
{ "presets": ["react", "es2017", "stage-3"] } // causes me test failures in node
{ "presets": ["react", "es2017", "stage-3", "es2015"] } // node tests pass, but in browser Object.values is not a function
{ "presets": ["react", "es2017", "stage-3", "es2015", "stage-2"] } // node tests pass, but browser error
{ "presets": ["react", "es2017", "stage-3", "es2016", "es2015"] } // node tests pass, but browser error
{ "presets": ["react", "es2015", "es2016", "es2017", "stage-3"] } // node tests pass, but browser error

I'm not sure if the order of presets matter so I tried a few things.

@bcowgill

This comment has been minimized.

Copy link
Author

bcowgill commented Jun 16, 2016

Well I solved it, found a shim.
Might be an idea to document which shims are needed on the docs page and/or add them as npm dependencies

npm install object.values

// Shim.js
import values from 'object.values');
if (!Object.values) {
values.shim();
}

or npm install es7-shim to get it all

@bettiolo

This comment has been minimized.

Copy link
Owner

bettiolo commented Jun 16, 2016

Thank you very much for your feedback! This npm package was meant to target node 5 but I will expand the scope to work well with the browsers.

This is the test covering the case and it works in node 5 which was the original target of the preset
https://github.com/bettiolo/babel-preset-es2017/blob/master/test/es2017.test.js#L19-L21

When I need to transpile my ES2017 code to ES5 I use this webpack configuration:

  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'babel',
        query: {
          presets: ['es2015', 'es2017', 'react'],
          plugins: ['transform-runtime', 'transform-decorators-legacy', 'transform-class-properties'],
        },
      },
    ],
@bettiolo

This comment has been minimized.

Copy link
Owner

bettiolo commented Jul 28, 2016

The shims are added here: https://github.com/bettiolo/babel-preset-es2017/blob/v1.5.0/index.js#L27

I think that this may not work with webpack. I will review it the behaviour with it.

@bettiolo

This comment has been minimized.

Copy link
Owner

bettiolo commented Jul 28, 2016

I can confirm that Webpack with ES2017 preset will not load the shims defined here: https://github.com/bettiolo/babel-preset-es2017/blob/v1.5.0/index.js#L27

@OZZlE

This comment has been minimized.

Copy link

OZZlE commented Dec 9, 2018

why did you close this issue? what was the solution???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment