scullyio / scully

The Static Site Generator for Angular apps
https://scully.io/
MIT License
2.55k stars 257 forks source link

Cannot read property 'search' of null #1402

Open alessandro-tucci-visiontech opened 3 years ago

alessandro-tucci-visiontech commented 3 years ago

🐞 Bug report

ng add @scullyio/init terminates uncorrectly with Cannot read property 'search' of null. I see that another similar issue was opened (#1168) but I'm not seeing any solution. W.r.t. this other issue (#1288), the name of my Angular project is something like xyz-showcase (yes, with the hyphen)

Description

🔬 Minimal Reproduction

Just run ng add @scullyio/init on the already-existing Angular project where I want to integrate scully

💻Your Environment

Angular Version:


Angular CLI: 11.2.14
Node: 15.14.0
OS: win32 x64

Angular: undefined
...
Ivy Workspace: No

Package                             Version
-------------------------------------------------------------
@angular-devkit/architect           0.1102.14
@angular-devkit/build-angular       0.1102.14
@angular-devkit/core                11.2.14
@angular-devkit/schematics          11.2.14
@angular/cli                        11.2.14
@angular/common                     11.2.14
@angular/compiler-cli               11.2.14
@angular/google-maps                12.0.2
@angular/language-service           11.2.14
@angular/platform-browser           11.2.14
@angular/platform-browser-dynamic   11.2.14
@angular/router                     11.2.14
@schematics/angular                 11.2.14
@schematics/update                  0.1102.14
typescript                          4.1.5

Scully Version:

    "@scullyio/init": "~1.1.4",
    "@scullyio/ng-lib": "~1.0.0",
    "@scullyio/scully": "~1.0.0",

🔥 Exception or Error


Skipping installation: Package already installed
Cannot read property 'search' of null
alessandro-tucci-visiontech commented 3 years ago

I partly managed to backtrace the problem. As we can see from here: https://github.com/scullyio/scully/blob/cbd940cf0f7db9f4a5b658b69f0a1b6fbebadde5/libs/scully-schematics/src/ng-add/index.ts#L25

and here: https://github.com/scullyio/scully/blob/cbd940cf0f7db9f4a5b658b69f0a1b6fbebadde5/libs/scully-schematics/src/ng-add/package-config.ts#L56

Scully's schematics are requiring the presence of @angular/core in the dependencies section of the package.json file. It is a requirement that should be added to the doc, since an explicit @angular/core dependency is not required for a generic Angular project to work.

However, there is still something missing. Now, I'm receiving this error:

  Skipping installation: Package already installed
    ⚠️  Skipping polyfills.ts
    Install ng-lib
    ✅️ Added dependency
UPDATE package.json (1717 bytes)
√ Packages installed successfully.
Cannot set property 'scully' of undefined
alessandro-tucci-visiontech commented 3 years ago

Another implicit requirement: the package.json file is required to provide a script section, as we can see here: https://github.com/scullyio/scully/blob/cbd940cf0f7db9f4a5b658b69f0a1b6fbebadde5/libs/scully-schematics/src/scully/index.ts#L31

Therefore, I was able to add the schematics by adding:

"scripts": {}

to my package.json file

SanderElias commented 3 years ago

@alessandro-tucci-visiontech Thanks for the thorough description. I'll be putting those issues on our to-do

SanderElias commented 2 years ago

@Jefiozie Did we already address this in our schematic updates?

Jefiozie commented 2 years ago

No I don't think so, assigning it to me for investigation

SanderElias commented 2 years ago

This seems also related to #1520. Not the same issue, but e might be able to solve both with the same solution.