Sonar-scanner cli failing to analyze CSS

I’m encountering errors when running the sonar-scanner. It appeared today and I haven’t found any topic discussing it yet.

Details:

  • runtime:
    • SonarScanner 4.5.0.2216
    • Java 11.0.6 AdoptOpenJDK (64-bit)
    • Linux 4.19.78-coreos amd64
    • Gitlab CI on gitlab.com

Error observed:

INFO: Sensor SonarCSS Rules [cssfamily]
ERROR: (node:47) ExperimentalWarning: The ESM module loader is experimental.
ERROR: internal/modules/run_main.js:54
ERROR:     internalBinding('errors').triggerUncaughtException(
ERROR:                               ^
ERROR: 
ERROR: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for /builds/gaspacchio/back-to-the-future/.scannerwork/css-bundle/bin/server
ERROR:     at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:65:15)
ERROR:     at Loader.getFormat (internal/modules/esm/loader.js:113:42)
ERROR:     at Loader.getModuleJob (internal/modules/esm/loader.js:244:31)
ERROR:     at processTicksAndRejections (internal/process/task_queues.js:97:5)
ERROR:     at async Loader.import (internal/modules/esm/loader.js:178:17) {
ERROR:   code: 'ERR_UNKNOWN_FILE_EXTENSION'
ERROR: }
ERROR: CSS rules were not executed. Failed to start server (60s timeout)
org.sonarsource.nodejs.NodeCommandException: Failed to start server (60s timeout)
	at org.sonar.css.plugin.server.CssAnalyzerBridgeServer.startServer(CssAnalyzerBridgeServer.java:110)
	at org.sonar.css.plugin.server.CssAnalyzerBridgeServer.startServerLazily(CssAnalyzerBridgeServer.java:173)
	at org.sonar.css.plugin.CssRuleSensor.execute(CssRuleSensor.java:99)
	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:45)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:75)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:48)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:66)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:48)
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:68)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:438)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:434)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:392)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:126)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:58)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:52)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at com.sun.proxy.$Proxy0.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:61)
INFO: Sensor SonarCSS Rules [cssfamily] (done) | time=61472ms

(...)

WARN: Failed to close stylelint-bridge server
java.net.ConnectException: Failed to connect to /127.0.0.1:42541
	at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:265)
	at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:183)
	at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.java:224)
	at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.java:108)
	at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.java:88)
	at okhttp3.internal.connection.Transmitter.newExchange(Transmitter.java:169)
	at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:41)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
	at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
	at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
	at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
	at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:221)
	at okhttp3.RealCall.execute(RealCall.java:81)
	at org.sonar.css.plugin.server.CssAnalyzerBridgeServer.callClose(CssAnalyzerBridgeServer.java:271)
	at org.sonar.css.plugin.server.CssAnalyzerBridgeServer.clean(CssAnalyzerBridgeServer.java:260)
	at org.sonar.css.plugin.server.CssAnalyzerBridgeServer.stop(CssAnalyzerBridgeServer.java:255)
	at org.sonar.core.platform.StartableCloseableSafeLifecyleStrategy.stop(StartableCloseableSafeLifecyleStrategy.java:38)
	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.stop(AbstractInjectionFactory.java:88)
	at org.picocontainer.behaviors.AbstractBehavior.stop(AbstractBehavior.java:179)
	at org.picocontainer.behaviors.Stored$RealComponentLifecycle.stop(Stored.java:141)
	at org.picocontainer.behaviors.Stored.stop(Stored.java:118)
	at org.picocontainer.DefaultPicoContainer.stopAdapters(DefaultPicoContainer.java:1048)
	at org.picocontainer.DefaultPicoContainer.stop(DefaultPicoContainer.java:803)
	at org.sonar.core.platform.ComponentContainer.stopComponents(ComponentContainer.java:152)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:111)
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:126)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:58)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:52)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at com.sun.proxy.$Proxy0.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.net.ConnectException: Connection refused (Connection refused)
	at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
	at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
	at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source)
	at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
	at java.base/java.net.Socket.connect(Unknown Source)
	at okhttp3.internal.platform.Platform.connectSocket(Platform.java:130)
	at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:263)
	... 47 common frames omitted
INFO: Analysis total time: 1:40.702 s

You can see the full log here: https://gitlab.com/gaspacchio/back-to-the-future/-/jobs/897241732

Steps to reproduce

IDK

Potential workaround

Not found yet.

Hello @Gaspacchio,

which version of Node.JS is installed for the analysis?

Good morning, I am having the same issue, with nodejs v.14.16.0

INFO: Load metrics repository
INFO: Load metrics repository (done) | time=45ms
INFO: Sonargraph Integration: Created 55 predefined and 0 custom metric(s)
INFO: Sensor CSS Metrics [cssfamily]
INFO: Sensor CSS Metrics [cssfamily] (done) | time=161ms
INFO: Sensor CSS Rules [cssfamily]
ERROR: internal/process/esm_loader.js:74
ERROR: internalBinding(‘errors’).triggerUncaughtException(
ERROR: ^
ERROR:
ERROR: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension “” for /var/lib/jenkins/jobs/sandbox/workspace/.scannerwork/css-bundle/bin/server
ERROR: at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:71:15)
ERROR: at Loader.getFormat (internal/modules/esm/loader.js:102:42)
ERROR: at Loader.getModuleJob (internal/modules/esm/loader.js:231:31)
ERROR: at async Loader.import (internal/modules/esm/loader.js:165:17)
ERROR: at async Object.loadESM (internal/process/esm_loader.js:68:5) {
ERROR: code: ‘ERR_UNKNOWN_FILE_EXTENSION’
ERROR: }
ERROR: CSS rules were not executed. Failed to start server (60s timeout)
org.sonarsource.nodejs.NodeCommandException: Failed to start server (60s timeout)
at org.sonar.css.plugin.server.CssAnalyzerBridgeServer.startServer(CssAnalyzerBridgeServer.java:113)
at org.sonar.css.plugin.server.CssAnalyzerBridgeServer.startServerLazily(CssAnalyzerBridgeServer.java:177)
at org.sonar.css.plugin.CssRuleSensor.execute(CssRuleSensor.java:99)
at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:59)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:389)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:385)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:354)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:144)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)

The same for me, any ideas when it will be fixed or what is the root cause?

Experienced the same issue with Node js v14.17.0, v13 and v15 too…

We also have this problem!

Details:
SonarScanner 4.6.2.2472
Java 11.0.11 AdoptOpenJDK (64-bit)
Linux 5.4.0-1047-azure amd64
Github Actions (Github runner)

Error:

INFO: Sensor CSS Rules [cssfamily]
ERROR: internal/process/esm_loader.js:74
ERROR: internalBinding('errors').triggerUncaughtException(
ERROR: ^
ERROR:
ERROR: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for /github/workspace/.scannerwork/css-bundle/bin/server
ERROR: at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:71:15)
ERROR: at Loader.getFormat (internal/modules/esm/loader.js:102:42)
ERROR: at Loader.getModuleJob (internal/modules/esm/loader.js:231:31)
ERROR: at async Loader.import (internal/modules/esm/loader.js:165:17)
ERROR: at async Object.loadESM (internal/process/esm_loader.js:68:5) {
ERROR: code: 'ERR_UNKNOWN_FILE_EXTENSION'
ERROR: }
ERROR: CSS rules were not executed. Failed to start server (60s timeout)
org.sonarsource.nodejs.NodeCommandException: Failed to start server (60s timeout)
 at org.sonar.css.plugin.server.CssAnalyzerBridgeServer.startServer(CssAnalyzerBridgeServer.java:113)
 at org.sonar.css.plugin.server.CssAnalyzerBridgeServer.startServerLazily(CssAnalyzerBridgeServer.java:177)
 at org.sonar.css.plugin.CssRuleSensor.execute(CssRuleSensor.java:99)
 at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:45)
 at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:75)
 at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:48)
 at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:66)
 at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:48)
 at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:68)
 at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
 at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
 at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:442)
 at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:438)
 at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:396)
 at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
 at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
 at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:128)
 at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
 at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
 at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:58)
 at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:52)
 at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.base/java.lang.reflect.Method.invoke(Unknown Source)
 at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
 at com.sun.proxy.$Proxy0.execute(Unknown Source)
 at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
 at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
 at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
 at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
 at org.sonarsource.scanner.cli.Main.main(Main.java:61)

INFO: Sensor CSS Rules [cssfamily] (done) | time=60714ms

Hi!

I have the same problem using the last docker image versions for both the server and the scanner.

It seems related to ts-node ERR_UNKNOWN_FILE_EXTENSION after adding "type": "module" to package.json · Issue #1171 · TypeStrong/ts-node · GitHub.

Anyone knows how to solve this?

1 Like

I can confirm this issue is a result of using ESModules, ie: setting “type”: “module” in package.json. The CSS Scanner is missing the file extension on an import and needs to be updated.

This is a blocking issue for me as I have a ton of scripts in module format, I am not going to convert it all to CommonJS because of SonarQube.

1 Like

@saberduck Any update on this? I am getting the same error but don’t see a solution posted here.

I am using the local instance of SonarQube.

Thanks!

@Gaspacchio were you able to find a solution?

Related issue: sonar-css#366.

I have the same issue on Node.js v.17 EAP and the latest SonarQube/SonarScanner.

hello,

I was finally able to reproduce this problem. It seems that we accidentally pickup package.json from the analyzed project, and if this project is setting type:module in package.json it will fail to start CSS analysis.

To workaround this issue you can configure the scanner work dir to be located outside of the analyzed project using sonar.working.directory property.

This will be also fixed in the next release of SonarQube 9.2 and soon it will be deployed on SonarCloud (I expect next week).

Sorry, that this took so long to address, we were not able to reproduce the problem on our side until very recently.

2 Likes

For reference, the fix was done in this PR Explicitly specify that we use commonjs modules by saberduck · Pull Request #2878 · SonarSource/SonarJS · GitHub, originally problem was located in sonar-css plugin, however, now CSS analysis is provided via sonar-javascript plugin.

This PR only makes usage of commonjs modules explicit, it was the case already implicitly, because commonjs is the default in Node.JS

2 Likes

Error seems not to be fixed. I get this error using latest sonar scanner cli in docker (full log in zip)

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 “type” field in package.json

It seems to be the same issue mentioned from saberduck, but just in css-bundle package.