Core-js: Object prototype may only be an Object or null: undefined

Created on 18 Sep 2019  路  12Comments  路  Source: zloirock/core-js

I hope this isn't a duplicate. Lately, we're seeing errors popping up in our monitoring system with this error message Object prototype may only be an Object or null: undefined.

The stack trace points to:

if (!NATIVE_ARRAY_BUFFER_VIEWS || !TypedArrayPrototype || TypedArrayPrototype === ObjectPrototype) {
   TypedArrayPrototype = TypedArray.prototype;
   if (NATIVE_ARRAY_BUFFER_VIEWS)
     for (NAME in TypedArrayConstructorsList) {
       //                | setPrototypeOf fails
       if (global[NAME]) setPrototypeOf(global[NAME].prototype, TypedArrayPrototype);
     }
 }

in array-buffer-view-core.

Were seeing this error pop up for the following browsers:

Screenshot 2019-09-18 at 16 29 26

So mostly mobile browsers but also some Chrome and Edge on Windows 10.

We're using this babel config:

module.exports = {
  presets: [
    [
      '@babel/env',
      {
        modules: NODE_ENV === 'test' ? 'auto' : false,
        useBuiltIns: 'entry',
        corejs: 3,
      },
    ],
    '@babel/react',
    '@babel/preset-flow',
  ],
  comments: true,
  plugins: [
    '@babel/transform-runtime',
    '@babel/plugin-transform-flow-strip-types',
    '@babel/plugin-proposal-object-rest-spread',
    '@babel/plugin-proposal-export-namespace-from',
    '@babel/plugin-proposal-class-properties',
    '@babel/plugin-proposal-function-bind',

    'lodash',
    'syntax-dynamic-import',

    ...(NODE_ENV === 'test' ? ['dynamic-import-node'] : []),
  ],
}

All plugins and presets are the latest versions.

This is our browser list:

{
  "browserslist": [
    "chrome >= 50",
    "firefox >= 52",
    "safari >= 10",
    "ie >= 11"
  ]
}

The questions

  • Can you either see an obvious error in our configuration?
  • If not, do you have any idea how to pinpoint the error? Maybe you've encountered similar situations before.
can't reproduce

Most helpful comment

At the top of my entrypoint is:

import 'core-js/stable'
import 'regenerator-runtime/runtime'

The only thing that loads before it is the webpack init stuff.

Deps (all latest as of writing):

@babel/core: 7.6.4
@babel/preset-env: 7.6.3
@babel/runtime-corejs3: 7.6.3
core-js: 3.3.3
webpack: 4.41.2

Sadly still not able to reproduce at all, and we've not had any customers reporting issues - just errors in our tracker (Rollbar)

All 12 comments

Something strange. Maybe a conflict with an alternative polyfill. Could you add a reproducible example?

I am also getting this bug. there is a line that mentions a webkit bug in the file: https://github.com/zloirock/core-js/blob/master/packages/core-js/internals/array-buffer-view-core.js#L114 could it be related?

@johnmarinelli nope.

I have been seeing this same error in production lately. Here is the Rollbar stacktrace I get:

Uncaught TypeError: Object prototype may only be an Object or null: undefined

TypeError: undefined
File (native) line (unknown) in setPrototypeOf
File ../node_modules/core-js/internals/array-buffer-view-core.js line 151 col 23 in Object.<anonymous>
if (global[NAME]) setPrototypeOf(global[NAME].prototype, TypedArrayPrototype);

File https://example.com/  line 1 col 27653 in a
File ../node_modules/core-js/internals/array-buffer.js line 7 col 27 in Object.<anonymous>
var NATIVE_ARRAY_BUFFER = require('../internals/array-buffer-view-core').NATIVE_ARRAY_BUFFER;

File https://example.com/  line 1 col 27653 in a
File ../node_modules/core-js/modules/es.array-buffer.constructor.js line 7 col 25 in Object.<anonymous>
var arrayBufferModule = require('../internals/array-buffer');

File https://example.com/  line 1 col 27653 in a
File ../node_modules/react-app-polyfill/stable.js line 95 col 1 in Object.<anonymous>
require("core-js/modules/es.array-buffer.constructor");

File https://example.com/  line 1 col 27653 in a
File https://example.com/static/js/main.f643d182.chunk.js  line 1 col 252 in Object.push.1134

I have unfortunately not been able to reproduce the issue. This error originates from a Create React App (v3.1.1) running with react-app-polyfill (v1.0.2).

react-app-polyfill initialisation (as instructed by the CRA docs):

// Polyfills create-react-app requires so that the site works in Internet Explorer 11.
import "react-app-polyfill/ie11";

// Polyfill stable JavaScript features
import "react-app-polyfill/stable";

Browserlist config in package.json:

"browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }

I'm not sure if this is an issue with core-js, CRA, or react-app-polyfill but this issue matched the closest the error and stacktrace that I have available. Like @frontendphil my traffic seems diverse but it seems to mostly originate from mobile browsers. This happens in about 0.7% of sessions. I am sorry for not being able reproduce and be of more help but I thought I would share some of my details, hopefully it can help narrow down the root of the issue.

Seeing the same thing here, without react. In our case it starts at the webpack bootstrap then follows the same stack trace

Uncaught TypeError: Object prototype may only be an Object or null: undefined
 File (native) line (unknown) in setPrototypeOf

File webpack:///./node_modules/core-js/internals/array-buffer-view-core.js line 128 col 23 in Object.<anonymous>
if (global[NAME]) setPrototypeOf(global[NAME].prototype, TypedArrayPrototype);

File webpack:///webpack/bootstrap line 89 col 22 in c
modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

File webpack:///./node_modules/core-js/internals/array-buffer.js line 4 col 27 in Object.<anonymous>
var NATIVE_ARRAY_BUFFER = require('../internals/array-buffer-view-core').NATIVE_ARRAY_BUFFER;

File webpack:///webpack/bootstrap line 89 col 22 in c
modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

File webpack:///./node_modules/core-js/modules/es.array-buffer.constructor.js line 4 col 25 in Object.<anonymous>
var arrayBufferModule = require('../internals/array-buffer');

File webpack:///webpack/bootstrap line 89 col 22 in c
modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

Windows Chrome 77 predominantly, with some other Chrome versions, Edge and one Android.

Was not able to reproduce either, tried a few different versions in Browserstack too.

Still no ideas. A reproducible example could be very useful. Could you add lists of your dependencies? Maybe you load something before core-js or it's at the top of your entry point?

At the top of my entrypoint is:

import 'core-js/stable'
import 'regenerator-runtime/runtime'

The only thing that loads before it is the webpack init stuff.

Deps (all latest as of writing):

@babel/core: 7.6.4
@babel/preset-env: 7.6.3
@babel/runtime-corejs3: 7.6.3
core-js: 3.3.3
webpack: 4.41.2

Sadly still not able to reproduce at all, and we've not had any customers reporting issues - just errors in our tracker (Rollbar)

I have been seeing this same error after updating core-js@3 from 2. 馃

Also seeing this error in our Rollbar tracker after moving from babel-polyfill to core-js 3. I have not been able to reproduce it.

I am seeing this error as well. Unfortunately our app is complex and a simple test case is probably hard to extract. Sorry about that. This is the #1 error on our dashboard. All Chrome, all Windows.

We're seeing this in our Sentry tracker as well. All Windows, mostly Chrome but one Edge instance as well.

I haven't seen this crop up again in about 2 months. All third party dependencies have remained unchanged. I have no clue what could have been causing this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Sequoia picture Sequoia  路  5Comments

kalvenschraut picture kalvenschraut  路  6Comments

devongovett picture devongovett  路  4Comments

flcl42 picture flcl42  路  4Comments

blondie63 picture blondie63  路  4Comments