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)
- unzip example project using
"type": "module"
in package.json.
sonartest.zip (22.1 KB) - add valid sonar-project,properties
- 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.