JS Parse Error: importing json files with ESM syntax

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension):
  • SonarQube 7.9.5
  • sonar-scanner 3.1.0
  • how is SonarQube deployed:
  • running locally (Apple M1 / zsh)
  • what are you trying to achieve:
  • I would like to resolve this parse error
  • what have you tried so far to achieve this:
  • I am not very familiar with various versions of Sonar. Since this is a parse error, my assumption is that if I stay on the same version of Sonar (7.9.5), I will be unable to resolve this issue.

I’ve provided the error message below with some data redacted for confidentiality:

ERROR: Unable to parse file: file:///<REDACTED>.mjs.js
ERROR: Parse error at line 1 column 51:

 1: import <REDACTED> from "../<REDACTED>.json" assert { type: 'json' };
                                                ^
 2: 
 3: export default function getAllowList(allowListKeys) {
 4:   if (!Array.isArray(allowListKeys)) throw Error(`TypeError: getAllowList - Expected String[] but received ${typeof allowListKeys}`);
 5:   return allowListKeys.reduce((accumulation, nextKey) => {
 6:     accumulation[nextKey] = <REDACTED>[nextKey];
 7:     return accumulation;
 8:   },{})
 9: }
10: export {
11:   <REDACTED>

Hey there.

Yes – you should upgrade to SonarQube 8.9 LTS (and then SonarQube 9.9 LTS) and see if the issue persists.

1 Like

Version 9.9 LTS resolved the issue.

Version 8.9 LTS contained a better error message suggesting that I upgrade to v9.

Thanks for the help, Colin!

1 Like

You’re welcome! Kudos for taking action. Don’t hesitate to create a new topic if you run into any unexpected changes after the upgrade (a lot changes in 3.5 years!)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.