devkit icon indicating copy to clipboard operation
devkit copied to clipboard

ng lint broken

Open f4nilo opened this issue 8 years ago • 1 comments

Bug Report or Feature Request (mark with an x)

- [x] bug report
- [ ] feature request

Area

- [x] devkit
- [ ] schematics

Versions

node: v10.1.0 npm: v5.6.0 OS: macOS Sierra v10.12.6 @angular-devkit/build-angular : v0.6.4

Repro steps

ng new repro-app
cd repro-app
ng lint

The log given by the failure

Cannot read property 'createProgram' of undefined
TypeError: Cannot read property 'createProgram' of undefined
    at Observable.rxjs_1.Observable.obs [as _subscribe] (/tmp/repro-app/node_modules/@angular-devkit/build-angular/src/tslint/index.js:40:44)
    at Observable.subscribe (/tmp/repro-app/node_modules/rxjs/internal/Observable.js:162:69)
    at /tmp/repro-app/node_modules/rxjs/internal/util/subscribeTo.js:22:31
    at Object.subscribeToResult (/tmp/repro-app/node_modules/rxjs/internal/util/subscribeToResult.js:7:45)
    at MergeMapSubscriber._innerSub (/tmp/repro-app/node_modules/rxjs/internal/operators/mergeMap.js:132:38)
    at MergeMapSubscriber._tryNext (/tmp/repro-app/node_modules/rxjs/internal/operators/mergeMap.js:129:14)
    at MergeMapSubscriber._next (/tmp/repro-app/node_modules/rxjs/internal/operators/mergeMap.js:112:18)
    at MergeMapSubscriber.Subscriber.next (/tmp/repro-app/node_modules/rxjs/internal/Subscriber.js:103:18)
    at MapSubscriber._next (/tmp/repro-app/node_modules/rxjs/internal/operators/map.js:92:26)
    at MapSubscriber.Subscriber.next (/tmp/repro-app/node_modules/rxjs/internal/Subscriber.js:103:18)

Desired functionality

ng lint fixed

Mention any other details that might be useful

With @angular-devkit/build-angular v0.6.3 ng lint works fine.

f4nilo avatar May 25 '18 03:05 f4nilo

Since a rollback was done, everything works fine with the v0.6.5...

Nevertheless, I took a look and it seems that the issue was due to a modification on angular-cli (angular-cli/packages/@angular/cli/utilities/require-project-module.ts file): https://github.com/angular/angular-cli/commit/e54213e4885cde23f5887c7aea68158090db074d#diff-a73addc4ea6dd3d35d407d4e989bec32

A call to resolveProjectModule('/tmp/repro-app', 'tslint') return /tmp/repro-app/tslint.json instead of /tmp/repro-app/node_modules/tslint/lib/index.js

// resolve dependencies within the target project
export function resolveProjectModule(root: string, moduleName: string) {
  return require.resolve(moduleName, { paths: [root] });
}

This function is indirectly called in the devkit/packages/angular_devkit/build_angular/src/tslint/index.ts file line 55:

      const projectTslint = requireProjectModule(
        getSystemPath(projectRoot), 'tslint') as typeof tslint;

A solution would be to remove the paths option to let resolve do a scan with the default resolution paths, or to append /node_modules to the root variable in order to ignore the tslint.json file.

f4nilo avatar May 26 '18 02:05 f4nilo