Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom angular 7 library with ionic 4 - Can't resolve '../@ionic/angular/dist/core.ngfactory' build prod error

We have built small angular 7/ionic 4 library that we want to use in multiple projects internally by installing through git url. Serving the project works correctly, all imports from library work fine. But when running ng build --prod I get the following error

ERROR in ./node_modules/edetail-core/edetail-core.ngfactory.js 
Module not found: Error: Can't resolve '../@ionic/angular/dist/core.ngfactory' in '/Users/user.name/Documents/ionic/edetails/node_modules/edetail-core'

I've tried different set ups - moving everything to devDependencies (main package.json), adding and removing packages from peerDependencies (library package.json). adding

"lib": {
    "entryFile": "src/public_api.ts",
    "externals": "@ionic/angular"
  }

(lib ng-package.json) but nothing helped. IonicModule gets imported from '@ionic/angular' in the main library module file (edetail-core.module.ts).

Here is ng-package.json

{
  "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
  "dest": "../../dist/edetail-core",
  "lib": {
    "entryFile": "src/public_api.ts"
  }
}

library package.json

{
  "name": "edetail-core",
  "version": "0.0.1",
  "peerDependencies": {
    "@angular/common": "^7.2.0",
    "@angular/core": "^7.2.0",
    "@ionic-native/core": "^5.0.0-beta",
    "rxjs": "^6.3.3",
    "@ionic/angular": "^4.0.0"
  }
}

main package.json

{
  "name": "edetail-core",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve edetail-test",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",        
    "npm-pack": "cd dist/edetail-core && npm pack",
    "prepare": "npm run build"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~7.2.0",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "@ionic-native/core": "^5.0.0",
    "@ionic-native/splash-screen": "^5.0.0",
    "@ionic-native/status-bar": "^5.0.0",
    "@ionic/angular": "^4.0.0",
    "@ng-bootstrap/ng-bootstrap": "^4.0.0",
    "bootstrap": "^4.1.3",
    "core-js": "^2.5.4",
    "rxjs": "~6.3.3",
    "scss-bundle": "^2.4.0",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular-devkit/build-ng-packagr": "~0.13.0",
    "@angular/cli": "~7.3.1",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@ionic/angular-toolkit": "~1.2.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.1.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "ng-packagr": "^4.2.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tsickle": ">=0.34.0",
    "tslib": "^1.9.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.2"
  },
  "files": [
    "dist"
  ]
}

Any help very much appreciated!

like image 403
Patrycja Czerwińska Avatar asked Feb 20 '19 13:02

Patrycja Czerwińska


1 Answers

Just add line "@ionic/*": ["node_modules/@ionic/*"] to paths in your tsconfig.json / tsconfig.app.json files

{
    ...
    "compilerOptions": {
        "paths": {
            "@angular/*": ["node_modules/@angular/*"],
            "@ionic/*": ["node_modules/@ionic/*"],
            ...
         }
    }
    ...
}

like image 126
Alexey Petushkov Avatar answered Sep 30 '22 12:09

Alexey Petushkov