How do I get module resolution to search parent directories when using the TypeScript Compiler API?

16 Views Asked by At

I am generating some code using ts-morph and I want to parse a file in one of my dependencies.

I tried using ts.resolveModuleName but this does not search in the parent directories:

              const x = ts.resolveModuleName(
                "@pulumi/aws",
                "",
                project.compilerOptions.get(),
                project.getModuleResolutionHost(),
              );
              console.log(x);

logs:

{
  resolvedModule: undefined,
  failedLookupLocations: [
    'node_modules/@pulumi/aws/package.json',
    'node_modules/@pulumi/aws.ts',
    'node_modules/@pulumi/aws.tsx',
    'node_modules/@pulumi/aws.d.ts',
    'node_modules/@pulumi/aws/index.ts',
    'node_modules/@pulumi/aws/index.tsx',
    'node_modules/@pulumi/aws/index.d.ts',
    'node_modules/@types/pulumi__aws/package.json',
    'node_modules/@types/pulumi__aws.d.ts',
    'node_modules/@types/pulumi__aws/index.d.ts',
    'node_modules/@pulumi/aws/package.json',
    'node_modules/@pulumi/aws.js',
    'node_modules/@pulumi/aws.jsx',
    'node_modules/@pulumi/aws/index.js',
    'node_modules/@pulumi/aws/index.jsx'
  ],
  affectingLocations: [
    '/Users/jason/src/bottech/pulumix/packages/pulumix-aws/package.json'
  ],
  resolutionDiagnostics: undefined,
  node10Result: undefined
}

compilerOptions.moduleResolution is NodeNext.

I want it to also look in /Users/jason/src/bottech/pulumix/node_modules like it does when using tsc.

What is it that I am missing to get it to behave like the normal resolution algorithm?

0

There are 0 best solutions below