CSS Scanner failing in project with type module

I am encountering an ERR_UNKNOWN_FILE_EXTENSION executiong sonarsource/sonar-scanner-cli with my npm project. Cause seems to be a problem loading the CssAnalyzerBridgeServer into a NodeJS project with type: module in package.json

ERROR: node:internal/errors:477
ERROR:     ErrorCaptureStackTrace(err);
ERROR:     ^
ERROR:
ERROR: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for /usr/src/.scannerwork/css-bundle/bin/server. Loading extensionless files is not supported inside of "type":"module" package.json contexts. The package.json file /usr/src/package.json caused this "type":"module" context. Try changing /usr/src/.scannerwork/css-bundle/bin/server to have a file extension. Note the "bin" field of package.json can point to a file with an extension, for example {"type":"module","bin":{"server":"./.scannerwork/css-bundle/bin/server.js"}}
ERROR:     at new NodeError (node:internal/errors:387:5)
ERROR:     at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:76:11)
ERROR:     at defaultGetFormat (node:internal/modules/esm/get_format:118:38)
ERROR:     at defaultLoad (node:internal/modules/esm/load:81:20)
ERROR:     at nextLoad (node:internal/modules/esm/loader:165:28)
ERROR:     at ESMLoader.load (node:internal/modules/esm/loader:608:26)
ERROR:     at ESMLoader.moduleProvider (node:internal/modules/esm/loader:464:22)
ERROR:     at new ModuleJob (node:internal/modules/esm/module_job:63:26)
ERROR:     at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:483:17)
ERROR:     at ESMLoader.getModuleJob (node:internal/modules/esm/loader:441:34) {
ERROR:   code: 'ERR_UNKNOWN_FILE_EXTENSION'
ERROR: }
ERROR: CSS rules were not executed. Failed to start server (60s timeout)
  1. unzip example project using "type": "module" in package.json.
    sonartest.zip (22.1 KB)
  2. add valid sonar-project,properties
  3. execute docker run --rm -v "$(pwd):/usr/src" sonarsource/sonar-scanner-cli

Workaround is to remove the property from the package.json during scanning. The PR Explicitly specify that we use commonjs modules by saberduck · Pull Request #2878 · SonarSource/SonarJS · GitHub seems to have already addressed the problem, but it did not completely solve the behavior.

hello @AnWeber ,

which version of SonarQube do you use? This was supposed to be fixed in SonarQube 9.2

I tested it with latest of sonar-scanner-cli docker. See logs in zip => SonarScanner 4.7.0.2747. SonarQube is Version 8.9.8 (build 54436). Are resources of the SonarQube Server used?

Yes, analyzers are provided by the SonarQube server, scanner downloads them during the scan. You would need to use more up-to-date SonarQube, latest is 9.8

Thanks.

1 Like