简体   繁体   中英

Angular cli library typescript paths don't work

I have an angular cli project, and created a new library:

ng g library test

Now, in the tsconfig.json file, I added the following paths options:

{
  "compileOnSave": false,
  "compilerOptions": {
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "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": {
      "@scope/name": ["projects/test/src/public_api.ts"]
    }
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}

But now when I try to use it in the application:

import { SomeComponent } from '@scope/name';

@NgModule({
  ...
})
export class AppModule {}

I get the error:

error TS2307: Cannot find module '@scope/name'.

You can use a file. You just have a typo. It should be:

"@scope/name": ["projects/test/src/public-api.ts"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM