1

I have multiple project in same Angular 8 app. In "root" tsconfig.json I add paths for @models

"compilerOptions": { "baseUrl": "./", "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, "downlevelIteration": true, "experimentalDecorators": true, "module": "esnext", "moduleResolution": "node", "importHelpers": true, "target": "es2015", "typeRoots": ["node_modules/@types"], "lib": ["es2018", "dom"], "paths": { "@models": ["projects/shared/models"] <=== this } }, 

I Import from index.ts barrel

export * from "./users/user-profile.model"; export * from "./users/users.model"; 

When I try In any component import model from @models

import { IUser } from "@models"; 

I get error

error TS2307: Cannot find module '@models'

But when I try to import it directly from the barrel, working ok

In every of my project, I also have tsconfig.app.json, but I only add the path to the root

1
  • "@models": ["projects/shared/models"] shoulde be replaced with "@models": ["projects/shared/models/index.ts"] in tsconfig.json file Commented Dec 10, 2019 at 10:24

3 Answers 3

1

Problem was in VS code, after multiple restarts, everything is working

Sign up to request clarification or add additional context in comments.

Comments

0

"@models": ["projects/shared/models"] should be replaced with "@models": ["projects/shared/models/index.ts"] in tsconfig.json file or you can write like below also

 "@models": [ "projects/shared/models/*" ], 

5 Comments

can u please share a stackblitz link for further investigation?
i will try, but this is very big app, i try to make example
Can you share the tsconfig.app.json. Please check what is the base url set in tsconfig.app.json also
this is the tsconfig.app.json { "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "../../out-tsc/app", "types": [] }, "files": ["src/main.ts", "src/polyfills.ts"], "include": ["src/**/*.ts"], "exclude": ["src/test.ts", "src/**/*.spec.ts"] }
I tried in my local and it works. Try restarting your editor please.
0

Try this

"paths": { "@models/*": ["projects/shared/models/*"] } 

After Updating tsconfig.json, restart the application

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.