ghidoz / angular2-jsonapi

A lightweight Angular 2 adapter for JSON API
200 stars 123 forks source link

Can not build master #247

Open hpawe01 opened 4 years ago

hpawe01 commented 4 years ago

On a fresh clone I executed npm install and then npm run build (as explained here: https://github.com/ghidoz/angular2-jsonapi#development) and I get following error:

ERROR: projects/angular2-jsonapi/src/services/json-api-datastore.service.ts(3,18): error TS2307: Cannot find module 'lodash-es/find'.
projects/angular2-jsonapi/src/models/json-api.model.ts(1,18): error TS2307: Cannot find module 'lodash-es/find'.
projects/angular2-jsonapi/src/models/json-api.model.ts(2,22): error TS2307: Cannot find module 'lodash-es/includes'.
projects/angular2-jsonapi/src/converters/date/date.converter.ts(1,26): error TS2307: Cannot find module 'date-fns'.

An unhandled exception occurred: projects/angular2-jsonapi/src/services/json-api-datastore.service.ts(3,18): error TS2307: Cannot find module 'lodash-es/find'.
projects/angular2-jsonapi/src/models/json-api.model.ts(1,18): error TS2307: Cannot find module 'lodash-es/find'.
projects/angular2-jsonapi/src/models/json-api.model.ts(2,22): error TS2307: Cannot find module 'lodash-es/includes'.
projects/angular2-jsonapi/src/converters/date/date.converter.ts(1,26): error TS2307: Cannot find module 'date-fns'.

The same error occurs when I perform ng build or ng build angular2-jsonapi

When I add the dependencies of projects/angular2-jsonapi/package.json as dev dependencies to package.json (npm i --save-dev date-fns lodash-es qs) the command runs through, but I don't know if this is the expected behavoir. Either we have to update the package.json or the README.md.

I think this has to do with the new structure? What do you say @magneticflux-?

magneticflux- commented 4 years ago

I can't reproduce this from a fresh checkout of master.

I'm using NodeJS 13.0.1, NPM 6.13.0, and Angular CLI 8.3.18. Could you post info about your environment?

hpawe01 commented 4 years ago

Steps to reproduce: docker pull node docker run --rm -it node /bin/bash git clone https://github.com/ghidoz/angular2-jsonapi.git cd angular2-jsonapi/ npm i; npm run build

Environment:

root@bbbb95b27ad9:/angular2-jsonapi# ./node_modules/.bin/ng --version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/

Angular CLI: 8.3.4
Node: 13.1.0
OS: linux x64
Angular: 8.2.6
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.803.4
@angular-devkit/build-angular      0.803.4
@angular-devkit/build-ng-packagr   0.803.4
@angular-devkit/build-optimizer    0.803.4
@angular-devkit/build-webpack      0.803.4
@angular-devkit/core               8.3.4
@angular-devkit/schematics         8.3.4
@angular/cli                       8.3.4
@ngtools/webpack                   8.3.4
@schematics/angular                8.3.4
@schematics/update                 0.803.4
ng-packagr                         5.5.0
rxjs                               6.5.3
typescript                         3.5.3
webpack                            4.39.2

root@bbbb95b27ad9:/angular2-jsonapi# node -v
v13.1.0
root@bbbb95b27ad9:/angular2-jsonapi# npm -v
6.12.1
magneticflux- commented 4 years ago

I was able to reproduce it using your instructions. It looks like I wasn't deleting all installed dependencies from a fresh checkout.

To fix the issue, run npm i && cd projects/angular2-jsonapi && npm i && cd ../.. and then npm run build. Both the Angular workspace and the library project need to be installed to build the library project.

hpawe01 commented 4 years ago

All right, with this procedure it works. But: I am a big fan of "convention over configuration" and since it is a common convention to just perform npm install in the root directory to install all needed dependencies to make a project run, I would love to have a way, that we only need to perform npm install in the root.

Two possibilities:

magneticflux- commented 4 years ago

I'm in favor of that. Here's the relevant Angular CLI documentation: https://angular.io/guide/npm-packages. I can't find any discussion on something like this though, which seems odd. I'd expect this to be a pretty common use-case.

hpawe01 commented 4 years ago

I think the reason is that they don't discuss angular libraries in detail, but only the available angular npm packages. I found a good article that discusses the angular library creation and publishing process: https://medium.com/angular-in-depth/creating-a-library-in-angular-6-part-2-6e2bc1e14121#822e

Root package.json This is the main package.json file for our library workspace. We use this to list our dependencies for both the application and the library. Any package that is needed to run or build either the application or the project must be in here.

So I would go with my second proposal and add the dependencies as dev dependencies to the root package.json.