Skip to content

Node.js-like module resolution doesn't follow parent paths #5102

Closed

Description

@heycalmdown

When I have following environment

  • parent
    • node_modules
      • my-proper-external-module
        • index.d.ts
        • index.js
    • my-application
      • index.ts (import m_p_e_m from 'my-proper-external-module')

It couldn't resolve where the my-proper-external-module is.

It should work according the proposal (#2338) and the source code(https://github.com/Microsoft/TypeScript/blob/b95e1ff6d8656693c80ac54a15893c3ad4859762/src/compiler/program.ts#L125).

I think it's come from by the directory which the loadModuleFromNodeModules have is empty string. It is an empty so it can not follow recursively.

Below is my tsconfig.json

{
  "compilerOptions": {
    "target": "ES5",
    "module": "commonjs",
    "moduleResolution": "node"
  },
  "files": [
    "./a.ts"
  ]
}

Activity

  1. heycalmdown commented on Oct 4, 2015

    @heycalmdown
    Author

    Got it.

    When if I compile like this

    tsc --project .
    

    doesn't work. But when if

    tsc --project $(pwd)
    

    works.

  2. mhegazy commented on Oct 6, 2015

    @mhegazy
    Contributor

    looks like this is fixed in master. can you give typescript@next a try?

  3. heycalmdown commented on Oct 10, 2015

    @heycalmdown
    Author
  4. alexeagle commented on Oct 14, 2015

    @alexeagle
    Contributor

    Same issue with some angular2 users who put their tsconfig.json under a src folder.
    Workaround is to run tsc from the parent directory and use the -p flag.

  5. mhegazy commented on Oct 27, 2015

    @mhegazy
    Contributor

    should be handled by #5275

  6. vladima commented on Oct 27, 2015

    @vladima
    Contributor

    fixed in e811fec

  7. mhegazy commented on Oct 27, 2015

    @mhegazy
    Contributor

    Alex Eagle (@alexeagle) and Kei Son (@heycalmdown) can you give tomorrow's typescript@next a try?

  8. heycalmdown commented on Oct 28, 2015

    @heycalmdown
    Author

    Sure, I was waiting your go sign.

  9. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions