ESLint — How to Fix “BigInt is not defined”

JavaScript supports the BigInt data type representing whole numbers larger than the Integer rage (2^53 - 1). An app of ours has database tables using a BigInt number for primary keys.

ESLint showed an issue that “BigInt is not defined” while mapping the primary key values from the database to BigInt values in JavaScript.

This tutorial shows you how to change your ESLint config to fix the unsupported BigInt warning.

ESLint Series Overview

  1. How to Fix “BigInt is not defined”

Fixing “'BigInt' is not defined”

When using the BigInt data type with ESLint, you may run into the following error message:

'BigInt' is not defined (eslintno-undef)  

You can fix this on your side by updating your ESLint configuration file. For example, you may use an ESLint JSON config stored in .eslintrc.json. Open this file in your editor and explicitly set the es2020 environment config to true:

{
  "env": {
    "es2020": true,  // <- activate “es2020” globals
    "browser": true,
    "node": true,
    "mocha": true
  }
  …
}

Activating the es2020: true setting in your ESLint’s env configuration tells the parser to recognize ES2020 globals. And recognizing ES2020 globals includes the BigInt class.

You may already have an es6: true configuration in the ESLint env object. You can replace the es6: true option with es2020: true.

ESLint Standard May Release A Fix (soon)

At the time of writing this tutorial (September 9th, 2020), there’s an open pull request on the eslint-config-standard repository to enable ES2020 globals. This includes BigInts and other recently introduced data types.

If you come along this issue and see the linked pull request is merged, you may want to check your project for outdated dependencies. You may bump the eslint-config-standard dependency to a newer version containing the ES2020 environment if a new version is available.


Mentioned Resources

Explore the Library

Find interesting tutorials and solutions for your problems.