Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

304
Views
"Parsing error: Unexpected token import" when accessing import.meta.url (Cloud9 IDE)

With the following node.js code:

import { fileURLToPath } from 'node:url';
import path from 'node:path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(fileURLToPath(import.meta.url));

I am seeing the following lint error relating to the import.meta.url reference:

enter image description here

This snippet is to replicate __filename and __dirname in ESM as per node.js guidance. The same error is given when using import.meta.url as follows... which is also in the official guidance:

import { readFileSync } from 'fs';
const buffer = readFileSync(new URL('./data.proto', import.meta.url));

I have looked at this but it doesn't solve my problem. This is specifically within the Cloud9 IDE... not the current AWS Cloud9 but a self-hosted Cloud9 based on this repo (last updated 4 years ago). The only guidance from (AWS) Cloud9 is on this page:

enter image description here

I can get certain basic rules to work using this .eslintrc file, e.g.

{
  rules: {
    semi: ["error", "never"]
  }
}

enter image description here

So I know that the config file is taking effect in the IDE. But can't see the appropriate rule to disable the "unexpected token import" error.

EDIT: the following seem relevant but I cannot determine if it has ever really reached a conclusion:

https://github.com/eslint/eslint/issues/12518

https://github.com/eslint/eslint/pull/13196

https://github.com/eslint/eslint/issues/13133

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is actually an educated guess, since I'm not using the Cloud9 IDE. If your .eslintrc file is being recognized, what you need to add there are the proper parser options, e.g.:

{
  "parserOptions": {
    "ecmaVersion": 2020,
    "sourceType": "module"
  },
  "rules": {
    "semi": ["error", "never"]
  }
}

The reason is that the ESLint parser treats by default all JavaScript sources as ES5 scripts, while the import.meta syntax is only allowed in modules since ECMAScript 2020.

Update

The setting "ecmaVersion": 2020 is supported in ESLint 6 onwards. Another option to have import.meta recognized is using a custom parser like Babel. The packages to install for the Babel parser are @babel/core and @babel/eslint-parser. And the relevant settings in .eslintrc are here:

{
  "parser": "@babel/eslint-parser",
  "parserOptions": {
    "ecmaVersion": 2020,
    "requireConfigFile": false
},

Note: I couldn't find out which versions of ESLint are supported by the Babel parser in the documentation in their repo (link above). I can only see in the code that ESLint 7 and 8 are supported. If the current version of Babel does not work with your version of ESLint, you may have to try installing older releases and see if they work. And in that case, an additional plugin like syntax-import-meta may be required.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!