Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.

ERROR: Failed to find a source file matching path <path> in program created with <path_to_tsconfig> #786

Open
venttola opened this issue Jan 9, 2019 · 6 comments

Comments

@venttola
Copy link

venttola commented Jan 9, 2019

I want to report a bug.

SonarTS version: 5.0

Node.js version: 11.6.0

TypeScript version: 2.8.3

SonarQube version: 7.4

Reproducer

Logs

// logs of analysis if relevant
``` INFO: Analyzing 31 typescript file(s) with the following configuration file /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/databasehandler.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/middleware/priviledgechecker.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/models/discount.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/models/event.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/models/grouppayment.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/models/models.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/models/organization.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/models/participant-payment.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/models/participant.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/models/participantgroup.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/models/platoon.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/models/product.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/models/productselection.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/models/user.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/models/userpayment.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/routes/admin.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/routes/auth.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/routes/event.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/routes/group.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/routes/organization.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/routes/user.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/server.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/services/adminservice.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/services/authservice.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/services/eventservice.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/services/groupservice.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/services/mailerservice.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/services/organizationservice.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/services/paymentservice.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/services/userservice.ts in program created with /project/tsconfig.json
ERROR: Failed to find a source file matching path /project/src/utils/errorhandler.ts in program created with /project/tsconfig.json
INFO: 31 files analyzed out of 31

Expected behavior
Analysis should succeed.

I was able to analyze my project once, but then all of a sudden it did no longer find my source files. No analysis for my source files is found at my SonarQube instance.

Analysis in the same environment for other Typescript projects works without any issues.

@venttola
Copy link
Author

venttola commented Jan 9, 2019

Additional info:
Running the scanner without tsconfig.json. at project root seems to succeed, so here is my tsconfig.json:

{   
    "include": [ "src/**/*" ],
    "compilerOptions": {
        "noImplicitAny": true,
        "target": "es6",
        "rootDir": "src",
        "outDir": ".",
        "module":"commonjs",
        "moduleResolution":"node",
        "types": [
            // add node as an option
            "node"
         ],
        "typeRoots": [ "node_modules/@types" ],
        "lib": ["DOM","ES6","ScriptHost", "ES2015.Promise"]

    }
}

Is there something wrong with this?

@andrea-guarino-sonarsource
Copy link
Contributor

Hi @venttola,

Please, try to change outDir value to something else (like "./out").

I suspect it's because of outDir property in your tsconfig: it seems that the directory specified here ("." in your case) is automatically added to the excluded files. Hence all your files will be excluded by TypeScript compiler.

@venttola
Copy link
Author

That seemed to do trick, thanks for the help! I'm using Gulp for building, and I guess is somehow overrided the faulty value in tsconfig.json. I checked my other project's tsconfig.json and there the outDir option is a lot more sensible.

Just the confirm: This was a TypeScript compiler issue, which the plugin internally uses?

If this is the case, could it be mentioned in a little bit more clear way in the documentation of SonarTS -plugin?

ClydeDz added a commit to ClydeDz/robohash-avatars-npm that referenced this issue May 31, 2019
Context: Sonarcloud unable to detect declaration files.
Reference: SonarSource/SonarTS#786
@anandrajana
Copy link

anandrajana commented Nov 6, 2019

I'm getting same issue with react & typescript project. Is there any solution for this?

my sonar props
sonar.projectKey=ui-components
sonar.sources=src
sonar.test.inclusions=/*.test.ts,/.test.tsx,**/.test.js,**/*.test.jsx
sonar.tests=src
sonar.typescript.lcov.reportPaths=./coverage/lcov.info

and tsconfig.json is
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"types": ["react", "jest"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react",
"outDir": "build"
},
"include": [
"src"
]
}

@sivantha96
Copy link

sivantha96 commented Sep 24, 2020

I am getting the same errors in my Angular 9 project. Is there any solution?

Here is my tsconfig.app.json

{
  "extends": "./tsconfig.base.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": []
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ]
}

@saberduck
Copy link
Contributor

hello @sivantha96 , can you please post your problem on our community forum https://community.sonarsource.com/ ?
This is legacy repository and analysis is not done using this plugin anymore. It's likely your issue will be fixed in next SonarQube version 8.5 which will be released in few weeks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants