Skip to content
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

Typescript 3 --build ignores baseUrl #25682

Closed
marcos-diaz opened this issue Jul 16, 2018 · 5 comments
Closed

Typescript 3 --build ignores baseUrl #25682

marcos-diaz opened this issue Jul 16, 2018 · 5 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@marcos-diaz
Copy link

TypeScript Version: 3.0.0-rc

Search Terms: baseUrl

Code

{
  "compilerOptions": {
    "baseUrl": "./src",
    ...
  }
}

tsc --build tsconfig.json

Expected behavior:
Now that Typescript 3.0 compiler claims to be a also a simple project builder, I would expect compiled output to resolve absolute imports to itself based on baseUrl setting.

Actual behavior:
It still outputs unresolved require paths.

@mhegazy
Copy link
Contributor

mhegazy commented Jul 16, 2018

Can you share more details?

@mhegazy mhegazy added the Needs More Info The issue still hasn't been fully clarified label Jul 16, 2018
@marcos-diaz
Copy link
Author

marcos-diaz commented Jul 17, 2018

I can try, just imagine you have a project/module called fancylib, you possibly have a bunch of top level files at root level in your project, and a folder src with the actual code of the lib.

Then in the lib some files will reference other files, the easy way is to do relative imports, for example in fancyness.ts you would do import {Magic} from './utils', but some people argue that doing relative imports is a bad practice, that makes refactors harder, etc... so they would like to do absolute imports better, as import {Magic} from 'fancylib/utils' or simply import {Magic} from 'utils'.

This was only possible with Webpack/Gulp or other build systems, by using the tsconfig setting baseUrl, but was not possible with TSC since it WAS not a build tool, just a compiler, so it ignored baseUrl.

But now TSC is actually also a basic build tool, so is a reasonable expectation that if someone does import {Magic} from 'fancylib/utils' in a project/module called fancylib, with tsc --build ..., then TSC should output JS as const utils = require("<baseUrl>/utils"); utils.Magic ...

@mhegazy
Copy link
Contributor

mhegazy commented Jul 17, 2018

is this the same as #25613?

@marcos-diaz
Copy link
Author

I don't think is the same

@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

3 participants