Skip to content

Utilizing paths feature without baseUrl #28321

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
Timer opened this issue Nov 2, 2018 · 2 comments
Closed

Utilizing paths feature without baseUrl #28321

Timer opened this issue Nov 2, 2018 · 2 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@Timer
Copy link

Timer commented Nov 2, 2018

Hi!

I'm trying to figure out how to use the compilerOptions.paths behavior while retaining the default behavior of compilerOptions.baseUrl.

The following examples assume a folder structure like so:

my-app/
  tsconfig.json
  package.json
  src/
    index.ts
    something.ts

For example, if we want to support absolute imports via @/, we could configure paths like so:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"]
    }
  }
}

Unfortunately, this has the side effect of permitting import 'src/something'; since baseUrl is set to ..

It appears as if you can replicate the desired behavior by using the following configuration:

{
  "compilerOptions": {
    "baseUrl": "node_modules",
    "paths": {
      "@/*": ["../src/*"]
    }
  }
}

However, I'm not sure if this is functionally equivalent to the following example for all intents and purposes (assuming this worked):

{
  "compilerOptions": {
    "baseUrl": null, // undefined, whatever
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}

Can you confirm if baseUrl: 'node_modules' is identical to baseUrl: undefined? Or are these behaviors different?

Thanks!

@weswigham weswigham added the Question An issue which isn't directly actionable in code label Nov 3, 2018
@mheiber
Copy link
Contributor

mheiber commented Jun 12, 2019

We had the same question.

I'd like to turn this into a proposal.

Put actual/expected behavior here: #31869

@typescript-bot
Copy link
Collaborator

This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

4 participants