Skip to content

Unable to resolve directory dependencies #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
clayrisser opened this issue Aug 28, 2020 · 4 comments
Closed

Unable to resolve directory dependencies #119

clayrisser opened this issue Aug 28, 2020 · 4 comments

Comments

@clayrisser
Copy link

I am unable to resolve the dependency if I'm importing a directory with an index.ts file.

For example . . .
src/index.ts

export default class Hello {}

tests/index.ts

import Hello from '../src'

Instead, what I have to do to make it work is explicitly import the index, which is less ideal.
src/index.ts

export default class Hello {}

tests/index.ts

import Hello from '../src/index'

Here is the debug log for running the following command.

DEBUG=* dependency-tree --directory="." --list-form tests/index.ts
  tree given filename: tests/index.ts +0ms
  tree resolved filename: /home/codejamninja/Projects/generator-node-module-typescript/demo/tests/index.ts +1ms
  tree visited:  {} +0ms
  tree traversing /home/codejamninja/Projects/generator-node-module-typescript/demo/tests/index.ts +0ms
  precinct paperwork: stripping the dot from the extension to serve as the type +0ms
  precinct paperwork: setting the module type +0ms
  precinct paperwork: invoking precinct +0ms
  precinct options given:  { includeCore: false, type: 'ts' } +0ms
  precinct module type:  ts +0ms
  typescript-eslint:typescript-estree:createSourceFile Getting AST without type information in TS mode for: /home/codejamninja/Projects/generator-node-module-typescript/demo/estree.ts +0ms
  tree extracted 1 dependencies:  [ '../src/index' ] +9ms
  cabinet Given filename: /home/codejamninja/Projects/generator-node-module-typescript/demo/tests/index.ts +0ms
  cabinet which has the extension: .ts +0ms
  cabinet found a resolver for .ts +0ms
  cabinet performing a typescript lookup +0ms
  cabinet given typescript config:  undefined +0ms
  cabinet no tsconfig given, defaulting +0ms
  cabinet processed typescript config:  undefined +0ms
  cabinet processed typescript config type:  undefined +0ms
  cabinet with options:  { module: 2 } +0ms
  cabinet result: /home/codejamninja/Projects/generator-node-module-typescript/demo/src/index.ts +1ms
  cabinet resolved path for ../src/index: /home/codejamninja/Projects/generator-node-module-typescript/demo/src/index.ts +0ms
  tree cabinet-resolved all dependencies:  [
  '/home/codejamninja/Projects/generator-node-module-typescript/demo/src/index.ts'
] +2ms
  tree given filename: /home/codejamninja/Projects/generator-node-module-typescript/demo/tests/index.ts +11ms
  tree resolved filename: /home/codejamninja/Projects/generator-node-module-typescript/demo/tests/index.ts +0ms
  tree visited:  {
  '/home/codejamninja/Projects/generator-node-module-typescript/demo/tests/index.ts': []
} +0ms
  tree traversing /home/codejamninja/Projects/generator-node-module-typescript/demo/src/index.ts +0ms
  precinct paperwork: stripping the dot from the extension to serve as the type +11ms
  precinct paperwork: setting the module type +0ms
  precinct paperwork: invoking precinct +0ms
  precinct options given:  { includeCore: false, type: 'ts' } +0ms
  precinct module type:  ts +0ms
  typescript-eslint:typescript-estree:createSourceFile Getting AST without type information in TS mode for: /home/codejamninja/Projects/generator-node-module-typescript/demo/estree.ts +10ms
  tree extracted 0 dependencies:  [] +1ms
  tree cabinet-resolved all dependencies:  [] +1ms
  tree traversal complete Set {
  '/home/codejamninja/Projects/generator-node-module-typescript/demo/src/index.ts',
  '/home/codejamninja/Projects/generator-node-module-typescript/demo/tests/index.ts'
} +0ms
  tree deduped list of nonExistent partials:  [] +0ms
  tree list form of results requested +0ms
  tree final tree [
  '/home/codejamninja/Projects/generator-node-module-typescript/demo/src/index.ts',
  '/home/codejamninja/Projects/generator-node-module-typescript/demo/tests/index.ts'
] +0ms
/home/codejamninja/Projects/generator-node-module-typescript/demo/src/index.ts
/home/codejamninja/Projects/generator-node-module-typescript/demo/tests/index.ts
@clayrisser
Copy link
Author

Maybe this is related to issue #118

@mrjoelkemp
Copy link
Collaborator

hey! I notice in the output that you don't have a TSconfig defined. Is there a TS config option that would get this to work; if so, then you could supply the path to the TS config file and see if that works. If the file is pure commonjs, then it relies on the commonjs resolution algorithm (which handles the case you're mentioning). Since the "../src" module is going through TS proper: https://github.com/dependents/node-filing-cabinet/blob/master/index.js#L221, there might be a TS thing you need to set in a TS config. Let me know if that works at all.

@jeanlescure
Copy link

The following worked for me:

const tree = dependencyTree.toList(
  {
    filename,
    tsConfig: {
      compilerOptions: {
        allowSyntheticDefaultImports: true,
        module: 'commonjs',
      }
    },
    directory: './src',
    nonExistent: non,
  },
);

@mrjoelkemp
Copy link
Collaborator

Thanks for closing the loop @jeanlescure.

If anyone wants to add docs to the readme to clarify this or help someone with a similar issue in the future, then I'd gladly review a PR. Cheers!

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

No branches or pull requests

3 participants