What could be causing the `project.addSourceFilesAtPaths("../../tsconfig.json");` function to not retrieve the expected source files?

Using ts-morph to locate all the source files is crucial. The code snippet below demonstrates this:

The key code for this operation is as follows:

let tsmorph = require('ts-morph') 

const project = new tsmorph.Project();

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

const sourceFiles = project.getSourceFiles();

console.log(sourceFiles)  // This results in an empty array: []

Upon running

npx ts-node test/unit/ts-morph-test.ts
, the outcome is also an empty array.

Wondering why the correct results cannot be fetched?

You can view my code on CodeSandbox at the following link: https://codesandbox.io/s/2ntc8q

Examining the test project's code structure reveals that it clearly contains TypeScript files.

https://i.sstatic.net/FARfS.png

Answer №1

Consider implementing the following code snippet:

const tsmorph = require('ts-morph');

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Navigate through React components using React-Router to access class components

I'm encountering an issue when trying to route to a class component in React. Surprisingly, the routing works perfectly when using functional components. How can I successfully route to class components? As a beginner with react-router, I initially s ...

Creating a dedicated class or module specifically designed for handling import and export tasks is a highly efficient approach towards stream

Exploring different ways to import multiple classes into a single class file: import myClass1 'pathto1'; import myClass2 'pathto2'; import myClassn 'pathton'; Seeking a simpler method using one file (class export) with al ...

Guide on displaying several items from Laravel to Vue through the JavaScript filter method?

I need help transferring multiple objects from laravel to vue and filling my vue objects with information retrieved from the database. This is the data received from laravel: https://i.sstatic.net/2Hnk5.png Vue objects to be populated: storeName: {}, ...

Locate MongoDB documentation pertaining to arrays of objects with two specific fields

For instance, consider a Mongo db collection: [ { "user_id": 1, "lead_id": 901, ... ... }, { "user_id": 2, "lead_id": 902, ... ... }, { "user_id": 2, & ...

Is it possible to automatically adjust the text color to match the background color?

In my hypothetical scenario, I am part of a group chat where the owner has the ability to change the background color of the chat bubbles. Each user's username appears on top of their respective bubble in one of ten pre-assigned colors. However, not a ...

How to use Typescript to find the length of an array consisting of either strings or

I am trying to determine the length of a string or array, stored in a variable with the data type var stepData : string | string[]. Sometimes I receive a single string value, and other times I may receive an array of strings. I need the length of the array ...

When using `defineModel` in Vue, the returned value can be either an object or

defineModel() is a new feature introduced in Vue 3.4+. The official documentation provides the following example: const model = defineModel() model.value = 'hello' Initially, it appears that model is an object with a value property. However, th ...

What is the process for calling CSS from a separate directory?

I am looking to start building a website. Can someone advise on how to organize html, css, and javascript into separate folders? One folder will house files specifically for writing HTML and JavaScript, while the other folder will be dedicated solely to ...

Exploring Node and Express Request Query

I'm struggling with a specific endpoint setup in my code. // GET /api/logs/ app.get('/api/logs', function (req, res) { if (req.query.reverse === true) { res.send((mainModule.logs).reverse()); } else { res.send(mainModule.logs) ...

Decoding json data with targeted API keys

Looking for some assistance here. I've got a JSON data set that looks like this: [ { "positive": 2, "negative": 4 }, { "positive": 9, "negative": 18 }, { "positive": 6, "negative": 12 } ...

Canvas in the off state has been removed

My goal is to create a basic JavaScript library that includes rotating, translating, and scaling the canvas. One issue I am facing is when I rotate the canvas, half of the content ends up getting deleted because the center of rotation is set at (0, 0). I ...

The number input component that is meant to be reusable is experiencing functionality issues within the NUXT framework

I have a reusable input component that is being used in various places. Everything works well with the number input, but the issue arises when I completely clear the input. This action triggers a warning message in the console: [Vue warn]: Invalid prop: t ...

Search for information containing the keyword "mongo" within multiple related datasets

Since mongodb lacks support for join operations and I need to search across multiple business collections, services, and users, I have devised a solution that requires validation and possible improvements. The proposed schema flow is as follows: Business ...

Enhance the user experience with a personalized video player interface

I am facing difficulty in creating a responsive video with custom controls. While I understand that using a <figure></figure> element and setting the width to 100% makes the video responsive, I am struggling with making the progress bar also r ...

What causes the AJAX JSON script to output an additional 0?

Within my WordPress website, there is an AJAX function that reaches out to a PHP function in order to retrieve a specific value from a transient record stored in the Database. Whenever I trigger this function with jQuery, I successfully receive the result ...

Retrieve the current font style with Kendo UI Editor

Recently, I've been facing some challenges while working with the Kendo UI Editor. Specifically, I'm struggling to retrieve the current font style. My goal is to use JavaScript or jQuery to obtain the following values: Values I am looking for: ...

` `$(document.documentElement) selecting a particular element` `

Here is a function that I am working with: jQuery(document.documentElement).on('click touch', function(e) { // check if $(e.target) matches with $('ul#menu-navigation > li.menu-item') // or any child elements within this spe ...

Chrome has some issues with resizing the SVG Pattern element

Utilizing inline svgs, I have a svg circle filled with a pattern that should cover 100% of the container size. However, when the parent element is resized via JavaScript, the pattern no longer reflects the 100% width and height as expected. This issue seem ...

Mapping a JSON array within a static method in Angular2 and TypeScript

Struggling with the syntax to properly map my incoming data in a static method. The structure of my json Array is as follows: [ { "documents": [ { "title": "+1 (film)", "is-saved": false, ...

Is there a promise specified in the render function of Express node.js?

I have successfully rendered my index.html page, but now I need to send additional data via sockets. To do this effectively, I require a promise for the rendering process. Currently, the code is running synchronously, causing the socket data to be overwrit ...