angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Angular CLI can't find modules from locally installed library.

Open eestein opened this issue 8 years ago • 26 comments

Versions

Angular CLI: 1.7.4
Node: 7.7.3
OS: darwin x64
Angular: 5.1.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.7.4
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.3.2
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.4.2
webpack: 3.11.0

Repro steps

  • create a library
  • pack it using npm pack
  • install the tgz file using npm install --save path_to_tgz_file
  • run client project

Observed behavior

ERROR in ./src/app/app.module.ts
Module not found: Error: Can't resolve '@my_library/sdk' in '/Users/eestein/Documents/dev/my_library/sdk-front/samples/src/app'
ERROR in ./src/app/app.component.ts
Module not found: Error: Can't resolve '@my_library/sdk' in '/Users/eestein/Documents/dev/my_library/sdk-front/samples/src/app'

Desired behavior

Angular CLI would recognize the local package.

Mention any other details that might be useful (optional)

This is what I have in my package.json of the client project:

"@my_library/sdk": "file:///Users/eestein/Documents/dev/my_library/sdk-front/library/my_library-sdk-1.0.0-alpha.2.tgz",

If I open both offending files (app.component.ts and app.module.ts) in VSCode no error is shown. It looks like VSCode can find it, but Angular CLI can't.

This is my folder structure:

- library
   - library's code
   - *.tgz file
- samples
    - samples' code
    - package.json referencing the tgz file

eestein avatar May 29 '18 11:05 eestein

Anyone? I still can't fix it :/

Thanks!

eestein avatar Jun 04 '18 13:06 eestein

This seems like a bug but we'll need to look at a reproduction to find and fix the problem. Can you setup a minimal repro please?

You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

filipesilva avatar Jun 07 '18 17:06 filipesilva

@filipesilva Ok, I'm swamped with work right now, but I'll try to get it done by this Sunday/Monday. Thank you for your support.

eestein avatar Jun 08 '18 16:06 eestein

Hey @filipesilva, I've pushed the repro code here https://github.com/eestein/ng-extlib-bug-repro

I tried to remain pretty close to my real scenario. To run the project, use:

1 - Inside library folder: npm run build:local 2 - Inside samples folder: npm start

Please, let me know if you need anything else.

Thank you

eestein avatar Jun 18 '18 12:06 eestein

@filipesilva hey man, any news on this? Could you reproduce? Thank you

eestein avatar Jul 09 '18 22:07 eestein

I have the same issue with one of my projects. Another problem I ran into was that I was unable to run the CLI 6 conversion utility (the project was originally in Angular 5) - the conversion utility failed to resolve the locally installed modules. Removing the locally installed modules from package.json allowed the conversion utility to run.

sporritt avatar Jul 24 '18 01:07 sporritt

i should point out that removing the node_modules directory and running npm install again made this issue go away for me.

sporritt avatar Jul 24 '18 02:07 sporritt

I'm having the same issue, however removing the node_modules and running npm install again didn't fix it (I've also had to remove my local packages while using the conversion utility to migrate to Angular 6)

grsoares21 avatar Jul 26 '18 12:07 grsoares21

Hi @eestein I had a look at your repro and you seem to have a custom build step for you library. I'm guessing that something goes wrong while building/publishing the library and the module resolution does not work.

I can't really debug your build script but I can tell you that we use and test our setup listed in https://github.com/angular/angular-cli/wiki/stories-create-library. It uses ng-packagr to create the library, and also that we generally work with published libraries.

My advice to you is to look at how libraries generated with ng-packagr differ from yours, and that might help you find what's going wrong and adapt your build script. If I had to bet it's related to the library scope.

Hope this helps.

filipesilva avatar Aug 02 '18 17:08 filipesilva

I am also facing the same issue while installing angular package from locale using ng-packagr. but when I open app.module.ts in VSCode no error is shown. It looks like VSCode can find it, but Angular CLI can't.

Any help would be great.

Thanks

jainankit102 avatar Oct 23 '18 08:10 jainankit102

I am having a similar issue.

ERROR in src/app/app.module.ts(3,29): error TS2307: Cannot find module 'ngx-bootstrap/modal'.

afroguy16 avatar Nov 05 '18 14:11 afroguy16

Have you tried to build your library prior importing it? Use this ng build my-lib-name and as a result you should expect a new dist folder at the root of your project then retry the import.

iWooli avatar Nov 26 '18 14:11 iWooli

@iWooli, I updated angular/cli and everything is working fine. Thanks.

afroguy16 avatar Nov 26 '18 15:11 afroguy16

I am facing the same issue deleting node_modules and installing again doesn't fix my issue, upgrading the cli also doesn't fix my issue.

Dgs-asohail4 avatar Feb 24 '19 13:02 Dgs-asohail4

Hi, I created a library that export some classes used for datamodel.

index.ts export * from './lib/user';

export class User { id: number; email: string; name: string; lastAccess: Date; creationDate: Date; };

I made the build of the library and tried to use on my project, but i get an error: ERROR in src/app/@core/helpers/session.manager.ts(9,30): error TS2307: Cannot find module 'library-data'.

Someone know how to fix?

I already remove and reinstall packages but did'nt work.

miguelleitevieira avatar Feb 26 '19 11:02 miguelleitevieira

Hi, I created a library that export some classes used for datamodel.

index.ts export * from './lib/user';

export class User { id: number; email: string; name: string; lastAccess: Date; creationDate: Date; };

I made the build of the library and tried to use on my project, but i get an error: ERROR in src/app/@core/helpers/session.manager.ts(9,30): error TS2307: Cannot find module 'library-data'.

Someone know how to fix?

I already remove and reinstall packages but did'nt work.

Did you find a solution? I face the same problem. If you fixed it can you please share the solution?

NodiraIbrogimova avatar Mar 27 '19 07:03 NodiraIbrogimova

Hi, I created a library that export some classes used for datamodel. index.ts export * from './lib/user'; export class User { id: number; email: string; name: string; lastAccess: Date; creationDate: Date; }; I made the build of the library and tried to use on my project, but i get an error: ERROR in src/app/@core/helpers/session.manager.ts(9,30): error TS2307: Cannot find module 'library-data'. Someone know how to fix? I already remove and reinstall packages but did'nt work.

Did you find a solution? I face the same problem. If you fixed it can you please share the solution?

Yes, I created the library using Angular 6. Using that I could import library in Angular 7 projects too.

miguelleitevieira avatar Mar 27 '19 10:03 miguelleitevieira

Why is this closed? The issue is still happening

gp187 avatar May 12 '19 20:05 gp187

same here, just created a library and trying to use it, I get unresolved package while it is present in the node_modules directory

phil123456 avatar May 16 '19 09:05 phil123456

AH!!!!!! i added a baseURL in tsconfig.json in the package im importing:

"baseUrl": "./",

bharding777 avatar May 23 '19 13:05 bharding777