0

this is my project structure.project structure

testmultiimports-example is a generic test project of my library.

I want to change the import path for a generic import within a specific folder. I try to use a wildcard in a path mapping but doesn't work.

testmultiimports-example-> app.component.ts

import { Component } from '@angular/core';

// Now 
// import { Service1, Service2 } from 'testmultiimports';

// After I want import service like this 
import { Service1 } from 'testmultiimports/path1';
import { Service2 } from 'testmultiimports/path2';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent {
  
  public Service1Result: string;
  public Service2Result: string;

  constructor(s1: Service1, s2: Service2){
    this.Service1Result = s1.getResult();
    this.Service2Result = s2.getResult();
  }
}
ERROR-> Cannot find module 'testmultiimports/path1' or its corresponding type declarations IN NEW IMPORT MODE
----------------------------------------------------------------------------------------------
tsconfig.json structure is: 
{
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",   
    "target": "ES2022",
    "module": "ES2022",    
    "paths": {
      // "testmultiimports": ["dist/testmultiimports"],
      "testmultiimports/*": ["dist/testmultiimports/*"]
    }
}
-----------------------------------------------------------------------------------------------
angular.json: 
"tsConfig": "projects/testmultiimports-example/tsconfig.app.json"
----------------------------------------------------------------------------------------------
testmultiimports-example tsconfig.app.json:
{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "outDir": "../../out-tsc/app",
    "types": []
  },
  "files": [
    "src/main.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ]
}
--------------------------------------------------------------------------------------------------
  • what kind of lib are you trying to import ? did u tried . import { defineCustomElement } from 'my-library/dist/components/hello-world'; defineCustomElement(); – Stefani Toto Aug 23 '23 at 09:13

0 Answers0