question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

eslint parser flags import (in import.meta.url) as an error

See original GitHub issue

Tell us about your environment

vscode information Version: 1.39.2 Commit: 6ab598523be7a800d7f3eb4d92d7ab9a66069390 Date: 2019-10-15T15:33:40.634Z Electron: 4.2.10 Chrome: 69.0.3497.128 Node.js: 10.11.0 (vscode is apparently running a different node than the shell) V8: 6.9.427.31-electron.0 OS: Linux x64 4.15.0-66-generic

eslint is executed via: Dirk Baeumer’s vscode eslint extension: https://github.com/Microsoft/vscode-eslint

System configuration: Node version: v12.11.1 npm version: v6.12.1 Local ESLint version: Not found Global ESLint version: v6.6.0 (Currently used)

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration:

Configuration
env:
  node: true
  es6: true
  mocha: true # NOTE: Not all tests pass eslint.

parserOptions:
  ecmaVersion: 2018

rules:
  # Possible Errors
  # http://eslint.org/docs/rules/#possible-errors
  comma-dangle: [2, "only-multiline"]
  no-control-regex: 2
  no-debugger: 2
  no-console: 2
  no-dupe-args: 2
  no-dupe-keys: 2
  no-duplicate-case: 2
  no-empty-character-class: 2
  no-ex-assign: 2
  no-extra-boolean-cast : 2
  no-extra-parens: [2, "functions"]
  no-extra-semi: 2
  no-func-assign: 2
  no-invalid-regexp: 2
  no-irregular-whitespace: 2
  no-negated-in-lhs: 2
  no-obj-calls: 2
  no-proto: 2
  no-unexpected-multiline: 2
  no-unreachable: 2
  use-isnan: 2
  valid-typeof: 2
  no-var: 2
  object-curly-spacing: [2, "never"]

  # Best Practices
  # http://eslint.org/docs/rules/#best-practices
  no-fallthrough: 2
  no-octal: 2
  no-redeclare: 2
  no-self-assign: 2
  no-unused-labels: 2

  # Strict Mode
  # http://eslint.org/docs/rules/#strict-mode
  strict: [2, "global"]

  # Variables
  # http://eslint.org/docs/rules/#variables
  no-delete-var: 2
  no-undef: 2
  #no-unused-vars: [2, {"args": "after-used"}]
  no-unused-vars: [2, {"args": "none"}]     # don't complain about unused args

  # Node.js and CommonJS
  # http://eslint.org/docs/rules/#nodejs-and-commonjs
  no-mixed-requires: 2
  no-new-require: 2
  no-path-concat: 2
  no-restricted-modules: [2, "sys", "_linklist"]

  # Stylistic Issues
  # http://eslint.org/docs/rules/#stylistic-issues
  comma-spacing: 2
  eol-last: 2
  indent: [2, 2, {SwitchCase: 1}]
  keyword-spacing: 2
  max-len: [2, 100, 2, {ignoreComments: true, ignoreStrings: true, ignoreTemplateLiterals: true}]
  new-parens: 2
  no-mixed-spaces-and-tabs: 2
  no-multiple-empty-lines: [2, {max: 2}]
  no-trailing-spaces: 2
  quotes: [2, "single", "avoid-escape"]
  # semi: 2
  space-before-blocks: [2, "always"]
  space-before-function-paren: [2, "always"]
  # space-in-parens: [2, "never"]
  space-infix-ops: 2
  space-unary-ops: 2

  # ECMAScript 6
  # http://eslint.org/docs/rules/#ecmascript-6
  # arrow-parens: [2, "always"]
  arrow-spacing: [2, {"before": true, "after": true}]
  constructor-super: 2
  no-class-assign: 2
  # no-confusing-arrow: [2, {"allowParens": true}]
  no-const-assign: 2
  no-dupe-class-members: 2
  no-new-symbol: 2
  no-this-before-super: 2
  prefer-const: 2

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

import {createRequire} from 'module';
const require = createRequire(import.meta.url);

What did you expect to happen? no error flagged from referring to import.meta.url

What actually happened? Please include the actual, raw output from ESLint. (parsing error unexpected token: import) image

Are you willing to submit a pull request to fix this bug? if someone points me at the appropriate parsing code i’ll give it a try.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
runarbergcommented, Feb 5, 2020

import.meta is already in stage 3 and is implemented by all modern browsers except edge as well as node.

It notably replaces __dirname and __filename in native es modules in node. Meaning that if you want to get these values in a module you must use import.meta.

It is indeed annoying that the only reason to pull in babel as a dev dependency is because eslint is unable to parse import.meta.

2reactions
kaicataldocommented, Mar 13, 2020

I do want to note that our policy is to update core rules to not crash. Parser errors are not included in this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ESlint - import.meta causes Fatal Parsing Error - Stack Overflow
I just came across this issue too. Support for import.meta was added in eslint 7.2.0 (June 2020) however in order to make it...
Read more >
import.meta - JavaScript - MDN Web Docs
meta meta -property exposes context-specific metadata to a JavaScript module. It contains information about the module, such as the module's URL.
Read more >
import.meta.url - Parsing error: Unexpected token import
I note from the changelog that eslint was updated to accept the 'import' token in v.7.2.0. What am I doing wrong (or is...
Read more >
Working with Rules - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Parcel
Add a <script> tag. ... If you make an error in your code or configuration, Parcel displays beautiful diagnostics in your terminal ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found