Title: ng add fails to find app.module.ts when using custom tsconfig.json paths · Issue #12740 · angular/angular-cli · GitHub
Open Graph Title: ng add fails to find app.module.ts when using custom tsconfig.json paths · Issue #12740 · angular/angular-cli
X Title: ng add fails to find app.module.ts when using custom tsconfig.json paths · Issue #12740 · angular/angular-cli
Description: Bug Report or Feature Request (mark with an x) - [X ] bug report -> please search issues before submitting - [X ] feature request Whether this is a bug or a feature depends on whether or not custom paths in tsconfig.json are supported wi...
Open Graph Description: Bug Report or Feature Request (mark with an x) - [X ] bug report -> please search issues before submitting - [X ] feature request Whether this is a bug or a feature depends on whether or not custom...
X Description: Bug Report or Feature Request (mark with an x) - [X ] bug report -> please search issues before submitting - [X ] feature request Whether this is a bug or a feature depends on whether or not cus...
Opengraph URL: https://github.com/angular/angular-cli/issues/12740
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ng add fails to find app.module.ts when using custom tsconfig.json paths","articleBody":"### Bug Report or Feature Request (mark with an `x`)\r\n```\r\n- [X ] bug report -\u003e please search issues before submitting\r\n- [X ] feature request\r\n```\r\nWhether this is a bug or a feature depends on whether or not custom `paths` in `tsconfig.json` are supported with the Cli.\r\n\r\n### Command (mark with an `x`)\r\n```\r\n- [X ] add\r\n```\r\n\r\n### Versions\r\nAngular CLI: 7.0.2 \r\nNode: 10.8.0 \r\nOS: win32 x64 \r\nAngular: 7.0.0 \r\n... animations, common, compiler, compiler-cli, core, forms \r\n... http, language-service, platform-browser \r\n... platform-browser-dynamic, router \r\n\r\n### Repro steps\r\n- `ng new app-name` (pick defaults)\r\n- Add `\"paths\": { \"@app/*\": [\"src/app/*\"] }` to `tsconfig.json`\r\n- Update `main.ts` to use this new path\r\n `import { AppModule } from '@app/app.module';`\r\n `import { environment } from './environments/environment';`\r\n- `ng add @angular/material`\r\n- Select `Yes` for `? Set up browser animations for Angular Material?`\r\n\r\nRepository all set up to reproduce this error is available [here](https://github.com/seangwright/ng-cli-add-error-with-tsconfig-paths).\r\nJust clone and type `ng add @angular/material`.\r\n\r\n### The log given by the failure\r\n`Could not read Angular module file: /src/@app/app.module.ts`\r\n\r\n### Desired functionality\r\nCli handles custom paths in `tsconfig.json`.\r\n\r\n### Mention any other details that might be useful\r\nHere is where material tries to get the `app.module.ts` path\r\nhttps://github.com/angular/material2/blob/985774a4eaa14d1dcbf1ad96ab176043d38f433e/src/lib/schematics/ng-add/setup-project.ts#L56\r\n\r\nHere is where the path to `app.module.ts` is being calculated in the schematics code\r\nhttps://github.com/angular/angular-cli/blob/82f2bda2f59e4665611d1a75b51a62bae21ac340/packages/schematics/angular/utility/ng-ast-utils.ts#L78\r\n\r\nI believe the above link is what is causing the problem.\r\n\r\nI've always preferred absolute urls in Angular apps compared to the relative paths (which become very difficult to read for nested components).\r\n\r\nAdding custom `paths` to `tsconfig.json` works pretty well to solve this problem. VSCode works fine with it and the Cli has no other issues I've run into.\r\n\r\nIf using `paths` isn't officially supported does the Angular team recommend using relative paths like `import { MyApiService } from '../../../../../my-api.service'`?\r\n","author":{"url":"https://github.com/seangwright","@type":"Person","name":"seangwright"},"datePublished":"2018-10-24T20:21:41.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":11},"url":"https://github.com/12740/angular-cli/issues/12740"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7e0c17e4-281f-3d63-5dd8-dce081776734 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 85BC:3A1ACB:58ECDD:799B16:6964F557 |
| html-safe-nonce | 3fc8a533048106706c59560bb74fa3502ad03836dd095022c736e2773250aea0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NUJDOjNBMUFDQjo1OEVDREQ6Nzk5QjE2OjY5NjRGNTU3IiwidmlzaXRvcl9pZCI6IjMyNTA2NzQ3MzczNzIwMDE2MjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8452b11b1cef071a2eee8ce38b0a5414efa2704cd86e34308f1c915fe3d7dee7 |
| hovercard-subject-tag | issue:373661172 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular-cli/12740/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9301cfef23a3b2589b748e6b8fd04830caf953d10537eeffd8dd28e3c3064f07/angular/angular-cli/issues/12740 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9301cfef23a3b2589b748e6b8fd04830caf953d10537eeffd8dd28e3c3064f07/angular/angular-cli/issues/12740 |
| og:image:alt | Bug Report or Feature Request (mark with an x) - [X ] bug report -> please search issues before submitting - [X ] feature request Whether this is a bug or a feature depends on whether or not custom... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | seangwright |
| hostname | github.com |
| expected-hostname | github.com |
| None | 003e962bf5ca78f3f8f71db2461c6a7f9cfcbe99b480d6aeddaef78d33e9161a |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular-cli git https://github.com/angular/angular-cli.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 36891867 |
| octolytics-dimension-repository_nwo | angular/angular-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36891867 |
| octolytics-dimension-repository_network_root_nwo | angular/angular-cli |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 21cbf6733480c5c09366f15b8dc8b6953472172a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width