Why `project.addSourceFilesAtPaths("../../tsconfig.json");` cannot get the correct result source files?

45 Views Asked by At

I use ts-morph to find all the source files:

the key code:

let tsmorph = require('ts-morph') 

const project = new tsmorph.Project();

project.addSourceFilesAtPaths("../../tsconfig.json");

const sourceFiles = project.getSourceFiles();

console.log(sourceFiles)  // there get empty array:[]

when I run npx ts-node test/unit/ts-morph-test.ts: but there get empty array:[]

why it cannot get the correct results?

my code uploaded to codesandbox: https://codesandbox.io/s/2ntc8q

the test project code structure: you see it obviously has ts files.

enter image description here

1

There are 1 best solutions below

0
aircraft On BEST ANSWER

You could try below code:

let tsmorph = require('ts-morph')

const project = new tsmorph.Project();
project.addSourceFilesFromTsConfig('/Users/johnson/github_repo/for-compare-test/Gono/packages/core/tsconfig.json')