question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript {paths} are not taken into consideration

See original GitHub issue

Edit from maintainers: we want to support this — see https://github.com/facebook/create-react-app/issues/5585#issuecomment-451161631 for details!


Is this a bug report?

Yes.

Did you try recovering your dependencies?

NPM 5.6.0 Yarn 1.7.0

Which terms did you search for in User Guide?

paths, paths map, path mappings, typescript path, typescript paths

Environment

  System:
    OS: macOS High Sierra 10.13.6
    CPU: x64 Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
  Binaries:
    Node: 8.11.2 - ~/.nvm/versions/node/v8.11.2/bin/node
    Yarn: 1.7.0 - ~/.yarn/bin/yarn
    npm: 5.6.0 - ~/.nvm/versions/node/v8.11.2/bin/npm
  Browsers:
    Chrome: 69.0.3497.100
    Firefox: 61.0.1
    Safari: 12.0
  npmPackages:
    @types/react: ^16.4.18 => 16.4.18 
    react: ^16.6.0 => 16.6.0 
    react-dom: ^16.6.0 => 16.6.0 
    react-scripts: 2.0.6-next.c662dfb0

Steps to Reproduce

TypeScript {paths} in {compilerOptions} are not working.

  1. Clone cra-workspaces#cra-2
  2. yarn install at the root
  3. cd apps/cra
  4. yarn start

Expected Behavior

CRA should resolve the modules listed in {paths}.

Actual Behavior

CRA cannot resolve the modules listed in {paths}.

Reproducible Demo

cra-workspaces#cra-2, instructions listed above.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:28 (5 by maintainers)

github_iconTop GitHub Comments

29reactions
Timercommented, Jan 3, 2019

Closing as a duplicate of #5118.

TypeScript support will ship without support for baseUrl and paths. Sorry for any inconvenience! I know it’ll be a bit painful to switch back to relative paths.

Edit: we do want to support this in the future, it just didn’t make it into the initial release. See this comment: https://github.com/facebook/create-react-app/issues/5585#issuecomment-451161631.

26reactions
Timercommented, Jan 3, 2019

We’ve held this position for a long time. Allowing users to adjust the module resolution order is rather confusing and can lead to subtle bugs (i.e. aliasing something that conflicts with a npm package name).

It’s hard to get all tooling to agree on how the resolution is performed, as we need to consider: webpack, Jest, Flow, TypeScript itself, and other tooling end-users install.

This isn’t a hard no, but it’s likely we’ll only add support for absolute imports and not arbitrary aliasing (i.e. baseUrl but not paths).

Due to this complexity, we’ll ship support without paths & baseUrl and evaluate it at a later date.

Edit: we do want to support this in the future, it just didn’t make it into the initial release. See this comment: https://github.com/facebook/create-react-app/issues/5585#issuecomment-451161631.

Read more comments on GitHub >

github_iconTop Results From Across the Web

nodemon - Typescript paths not working in an Express project
The TypeScript compiler will be able to resolve the paths so this will compile without problems, however the JavaScript output will not be ......
Read more >
Typescript — How to solve the problem with unresolved path ...
Generally, what should be done can be summarized as follows: Take a look into tsconfig.json and check if there are path aliases defined...
Read more >
Documentation - Module Resolution - TypeScript
Module resolution is the process the compiler uses to figure out what an import refers to. Consider an import statement like import {...
Read more >
Typescript – How to solve the problem with unresolved path ...
Generally, what should be done can be summarized as follows: Take a look into tsconfig.json and check if there are path aliases defined...
Read more >
Restructure with ease thanks to Typescript path mappings
Imports are a key part of any Typescript project, enabling us to ... Fear not! ... Let's take a look at the first...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found