angular2-jsonapi icon indicating copy to clipboard operation
angular2-jsonapi copied to clipboard

Can not build master

Open hpawe01 opened this issue 5 years ago • 6 comments

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-?

hpawe01 avatar Nov 07 '19 14:11 hpawe01

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?

magneticflux- avatar Nov 07 '19 23:11 magneticflux-

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

hpawe01 avatar Nov 08 '19 09:11 hpawe01

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.

magneticflux- avatar Nov 08 '19 18:11 magneticflux-

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:

  • usage of postinstall script in package.json to install the library project dependencies
  • we add the library project dependencies as workspace dev-dependencies (in fact, the library project dependencies are dependencies that I need for development)

hpawe01 avatar Nov 11 '19 06:11 hpawe01

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.

magneticflux- avatar Nov 11 '19 20:11 magneticflux-

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.

hpawe01 avatar Nov 22 '19 22:11 hpawe01