Fixing import reserved keyword error with SublimeLinter-contrib-eslint in JS

Índice
  1. Introduction
  2. The Error
  3. The Solution
  4. Conclusion

Introduction

When working with JavaScript, it is common to use the import statement to bring in external modules or files. However, sometimes when using SublimeLinter-contrib-eslint, you may encounter an error related to the use of the import reserved keyword. In this article, we will discuss how to fix this error and continue using import statements in your JavaScript code.

The Error

The error may appear in your SublimeLinter console as something like "Parsing error: 'import' and 'export' may only appear at the top level" or "Parsing error: The keyword 'import' is reserved". This error occurs because SublimeLinter-contrib-eslint is using an older version of ECMAScript (ES) syntax, which does not support the import statement.

The Solution

To fix this error, you need to configure SublimeLinter-contrib-eslint to use the correct ES syntax version. Specifically, you need to tell the linter to use version 6 or higher, which includes support for import statements.

To do this, you need to create a .eslintrc file in your project directory (if you don't have one already). In this file, add the following code:

{
  "parserOptions": {
    "ecmaVersion": 6
  }
}

This tells the linter to use ES version 6 syntax, which includes support for import statements. Once you save this file, SublimeLinter-contrib-eslint should no longer show errors related to the import keyword.

Conclusion

Fixing the import reserved keyword error in SublimeLinter-contrib-eslint is a simple process. By updating the linter to use the correct ES syntax version, you can continue using import statements in your JavaScript code without any issues. Remember to always keep your linter up to date to avoid any potential errors in your code.

Click to rate this post!
[Total: 0 Average: 0]

Related posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Go up

Below we inform you of the use we make of the data we collect while browsing our pages. You can change your preferences at any time by accessing the link to the Privacy Area that you will find at the bottom of our main page. More Information