TypeScript {paths} are not taken into consideration
See original GitHub issueEdit 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.
- Clone cra-workspaces#cra-2
yarn install
at the rootcd apps/cra
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:
- Created 5 years ago
- Comments:28 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Closing as a duplicate of #5118.
TypeScript support will ship without support for
baseUrl
andpaths
. 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.
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 notpaths
).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.