dsherret / ts-morph

TypeScript Compiler API wrapper for static analysis and programmatic code changes.
https://ts-morph.com
MIT License
4.97k stars 195 forks source link

getModuleSpecifierSourceFile return undefined for import with #1508

Open teyma opened 8 months ago

teyma commented 8 months ago

Hi, I'm working on project that verify the architecture of other projects. I'm using ts-morph to read files and get imports from them.

Everything works fine expect for some imports that could not be found.

I'm using the method getModuleSpecifierSourceFile that returns undefined.

This is an example of an import that does not work.

import * as path from 'path';

This is how i initialize the project

const project = new Project({
   tsConfigFilePath: 'tsconfig.json',
});

project.addSourceFilesAtPaths('src/**/*.ts');

In the compiler options in my tsconfig, I'm using :

"module": "commonjs"

I tried to add "moduleResolution": "Node", but it didn't change anything.

Thanks in advance for your help.

nmitic commented 4 months ago

@teyma I am having the same issues, using the examples from the docs I am getting undefined. However I am running code in VS plugin env... Did you managed to make it work?