palantir / tslint

:vertical_traffic_light: An extensible linter for the TypeScript language
http://palantir.github.io/tslint/
Apache License 2.0
5.91k stars 887 forks source link

Upgrading to 5.12.0 breaks Angular build process #4410

Closed doronsever closed 5 years ago

doronsever commented 5 years ago

Bug Report

Actual behavior

When running Angular build after upgrading to 5.12.0 we get the following errors and warnings

WARNING in ./node_modules/typescript/lib/typescript.js
Module not found: Error: Can't resolve 'crypto' in '/Users/dorons/dev/management/mgmt-console/node_modules/typescript/lib'

WARNING in ./node_modules/source-map-support/source-map-support.js
Module not found: Error: Can't resolve 'fs' in '/Users/dorons/dev/management/mgmt-console/node_modules/source-map-support'

WARNING in ./node_modules/source-map-support/source-map-support.js
Module not found: Error: Can't resolve 'module' in '/Users/dorons/dev/management/mgmt-console/node_modules/source-map-support'

ERROR in ./node_modules/tslint/lib/utils.js
Module not found: Error: Can't resolve 'fs' in '/Users/dorons/dev/management/mgmt-console/node_modules/tslint/lib'
ERROR in ./node_modules/tslint/node_modules/resolve/lib/async.js
Module not found: Error: Can't resolve 'fs' in '/Users/dorons/dev/management/mgmt-console/node_modules/tslint/node_modules/resolve/lib'
ERROR in ./node_modules/tslint/node_modules/resolve/lib/sync.js
Module not found: Error: Can't resolve 'fs' in '/Users/dorons/dev/management/mgmt-console/node_modules/tslint/node_modules/resolve/lib'
ERROR in ./node_modules/source-map-support/source-map-support.js
Module not found: Error: Can't resolve 'path' in '/Users/dorons/dev/management/mgmt-console/node_modules/source-map-support'
ERROR in ./node_modules/tslint/node_modules/resolve/lib/async.js
Module not found: Error: Can't resolve 'path' in '/Users/dorons/dev/management/mgmt-console/node_modules/tslint/node_modules/resolve/lib'
ERROR in ./node_modules/tslint/node_modules/resolve/lib/node-modules-paths.js
Module not found: Error: Can't resolve 'path' in '/Users/dorons/dev/management/mgmt-console/node_modules/tslint/node_modules/resolve/lib'
ERROR in ./node_modules/tslint/node_modules/resolve/lib/sync.js
Module not found: Error: Can't resolve 'path' in '/Users/dorons/dev/management/mgmt-console/node_modules/tslint/node_modules/resolve/lib'

Expected behavior

No errros during build

JoshuaKGoldberg commented 5 years ago

👋 @doronsever - sorry to hear this is troubling you. This isn't something that's come up before and your error messages aren't enough info to go off of - is your repository something you can post a link to here that we could access?

Something to try: delete your node_modules directory and either package-lock.json or yarn.lock (whichever exists), then reinstall with npm i / yarn and try again?

This looks like your @types/node type definitions for Node aren't being found by TypeScript.

doronsever commented 5 years ago

@JoshuaKGoldberg I've upgraded to lastest types/node module (10.12.18) and I'm still getting the same errors.

I cannot give you access to our repo but if you need any other logs please let me know... When I'm moving back to 5.11.0 everything works as expected

JoshuaKGoldberg commented 5 years ago

Some clarifying questions:

doronsever commented 5 years ago
{
  "name": "mgmt-console",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "gulp": "gulp",
    "start": "node --max-old-space-size=5196 node_modules/@angular/cli/bin/ng serve  --host=0.0.0.0 --proxy-config proxy.conf.json",
    "start-prod": "ng serve --prod --proxy-config proxy.conf.json",
    "start-private-proxy": "node --max-old-space-size=5196 node_modules/@angular/cli/bin/ng serve  --host=0.0.0.0 --proxy-config private-proxy.conf.json",
    "start-private-proxy-noreload": "node --max-old-space-size=5196 node_modules/@angular/cli/bin/ng serve  --host=0.0.0.0 --proxy-config private-proxy.conf.json --live-reload false",
    "start-noreload": "node --max-old-space-size=5196 node_modules/@angular/cli/bin/ng serve   --proxy-config proxy.conf.json --live-reload false",
    "build": "node --max-old-space-size=5196 node_modules/@angular/cli/bin/ng build --prod --aot && gulp swExcludePathFix",
    "build-sourcemap": "node --max-old-space-size=5196 node_modules/@angular/cli/bin/ng build --prod --aot --source-map && gulp swExcludePathFix",
    "build-local": "ng build --prod --base-href /dist/ --deploy-url /dist/    ",
    "test": "jest --coverage || true",
    "test:c": "jest --runInBand --coverage",
    "test:watch": "jest --watch",
    "format:fix": "pretty-quick --staged",
    "lint": "ng lint",
    "e2e": "./node_modules/.bin/testcafe-live chrome e2e/tests/",
    "e2e:ci": "./node_modules/.bin/testcafe chrome:headless e2e/tests/ -S -s screenshots -u -r xunit:res.xml  || true",
    "lint:shared-lib": "ng lint shared-lib",
    "compodoc": "./node_modules/.bin/compodoc -p ./tsconfig.json --customFavicon ./src/favicon.ico --hideGenerator --name Sentinel-One",
    "serve:admin-portal": "ng serve admin-portal --open",
    "serve:admin-portal:proxy": "ng serve admin-portal --proxy-config proxy.conf.json --open",
    "build:admin-portal": "ng build admin-portal --prod --aot",
    "lint:admin-portal": "ng lint admin-portal",
    "test:admin-portal": "ng test admin-portal --source-map=false",
    "build:shared-lib": "ng build shared-lib --prod",
    "test:shared-lib": "ng test shared-lib --source-map=false"
  },
  "private": true,
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged",
      "post-commit": "git update-index -g"
    }
  },
  "lint-staged": {
    "*.ts": [
      "./node_modules/.bin/prettier  --config ./.prettierrc --write",
      "tslint --fix"
    ]
  },
  "dependencies": {
    "@angular/animations": "7.1.4",
    "@angular/cdk": "^7.2.0",
    "@angular/common": "7.1.4",
    "@angular/compiler": "7.1.4",
    "@angular/core": "7.1.4",
    "@angular/forms": "7.1.4",
    "@angular/http": "7.1.4",
    "@angular/material": "^7.2.0",
    "@angular/platform-browser": "7.1.4",
    "@angular/platform-browser-dynamic": "7.1.4",
    "@angular/platform-server": "7.1.4",
    "@angular/pwa": "^0.11.4",
    "@angular/router": "7.1.4",
    "@angular/service-worker": "7.1.4",
    "@ngrx/effects": "6.1.2",
    "@ngrx/router-store": "6.1.2",
    "@ngrx/store": "6.1.2",
    "@ngrx/store-devtools": "6.1.2",
    "@nguniversal/express-engine": "6.0.0",
    "@sentinel-one/font-mgmt": "1.2.8",
    "@types/angular": "^1.6.52",
    "@types/d3": "^5.5.0",
    "@types/lodash": "^4.14.119",
    "@types/mark.js": "^8.11.2",
    "ag-grid-angular": "^19.1.2",
    "ag-grid-community": "^19.1.3",
    "ag-grid-enterprise": "^19.1.3",
    "angular-sortablejs": "^2.6.0",
    "angular-svg-round-progressbar": "^2.0.0",
    "angular2-virtual-scroll": "^0.1.8",
    "angulartics2": "^2.5.0",
    "chevrotain": "^3.7.4",
    "classlist.js": "^1.1.20150312",
    "clipboard-polyfill": "^2.7.0",
    "copy-webpack-plugin": "^4.6.0",
    "core-js": "^2.6.1",
    "css-loader": "^1.0.1",
    "d3": "^5.7.0",
    "file-saver": "^1.3.8",
    "guid-typescript": "1.0.7",
    "hammerjs": "^2.0.8",
    "install": "^0.11.0",
    "interactjs": "^1.3.4",
    "lodash": "^4.17.11",
    "mark.js": "^8.11.1",
    "moment": "^2.23.0",
    "mydatepicker": "^2.6.6",
    "mydaterangepicker": "^4.2.1",
    "ng2-ace-editor": "^0.3.8",
    "ng2-nouislider": "^1.7.13",
    "ngx-auto-unsubscribe": "^2.3.0",
    "ngx-cookie": "^3.0.1",
    "ngx-cookie-service": "^1.0.10",
    "ngx-device-detector": "^1.3.5",
    "ngx-moment": "^3.3.0",
    "ngx-pipes": "^2.3.6",
    "ngx-take-until-destroy": "^2.2.1",
    "ngx-uploader": "^4.2.4",
    "ngx-validators": "^3.0.0",
    "node-sass": "^4.11.0",
    "nouislider": "^10.1.0",
    "raven-js": "^3.27.0",
    "rxjs": "^6.3.3",
    "rxjs-compat": "^6.3.3",
    "sortablejs": "^1.7.0",
    "web-animations-js": "^2.3.1",
    "webpack-dev-middleware": "^3.4.0",
    "webpack-dev-server": "^3.1.14",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.10.6",
    "@angular-devkit/build-ng-packagr": "^0.7.5",
    "@angular-devkit/core": "^0.6.8",
    "@angular/cli": "^7.1.4",
    "@angular/compiler-cli": "7.1.4",
    "@angular/language-service": "7.1.4",
    "@compodoc/compodoc": "^1.1.7",
    "@ngrx/schematics": "^6.1.2",
    "@sentinel-one/management-node-sdk": "^1.0.18",
    "@sentinel-one/mgmt-schematics": "^1.4.0",
    "@types/jasmine": "^2.8.14",
    "@types/jest": "^23.3.10",
    "@types/node": "^10.12.18",
    "add": "^2.0.6",
    "angular2-template-loader": "^0.6.2",
    "chalk": "^2.4.1",
    "codelyzer": "^4.5.0",
    "exports-loader": "^0.7.0",
    "fs": "0.0.1-security",
    "gulp": "^4.0.0",
    "gulp-replace": "^0.6.1",
    "husky": "^1.2.1",
    "istanbul-reports": "^1.5.1",
    "jest": "^23.6.0",
    "jest-preset-angular": "^6.0.2",
    "jest-sonar-reporter": "^2.0.0",
    "lint-staged": "^7.3.0",
    "ng-packagr": "^4.4.5",
    "ngx-wallaby-jest": "0.0.1",
    "npm-run-all": "^4.1.5",
    "prettier": "^1.15.3",
    "pretty-quick": "^1.7.0",
    "protractor": "^5.4.1",
    "rxjs-tslint": "^0.1.6",
    "testcafe": "^0.23.3",
    "testcafe-angular-selectors": "^0.3.1",
    "testcafe-live": "^0.1.4",
    "ts-node": "^7.0.1",
    "tsickle": "^0.33.1",
    "tslib": "^1.9.0",
    "tslint": "^5.12.0",
    "tslint-config-prettier": "^1.17.0",
    "tslint-jasmine-rules": "^1.5.1",
    "typescript": "3.1.6",
    "wallaby-webpack": "^3.9.12"
  }
}
JoshuaKGoldberg commented 5 years ago

@doronsever I can't repro your issues locally with a basic ng new --minimal project. npm run build and npm run lint work fine.

// gulpfile.js
const gulp = require("gulp");

gulp.task("default", (done) => {
    console.log("Hello!");
    done();
});

gulp.task("swExcludePathFix", (done) => {
    console.log("Hello!");
    done();
});
C:\Code\ngtest  (mgmt-console@0.0.0)
λ npm run build

> mgmt-console@0.0.0 build C:\Code\ngtest
> node --max-old-space-size=5196 node_modules/@angular/cli/bin/ng build --prod --aot && gulp swExcludePathFix

Date: 2018-12-30T11:10:36.759Z
Hash: da33b21c0147538991c0
Time: 16482ms
chunk {0} runtime.ec2944dd8b20ec099bf3.js (runtime) 1.41 kB [entry] [rendered]
chunk {1} main.fbc31409f55f230216fa.js (main) 174 kB [initial] [rendered]
chunk {2} polyfills.de3db41568411a33a7d2.js (polyfills) 37.5 kB [initial] [rendered]
chunk {3} styles.3bb2a9d4949b7dc120a9.css (styles) 0 bytes [initial] [rendered]
[06:10:37] Using gulpfile C:\Code\ngtest\gulpfile.js
[06:10:37] Starting 'swExcludePathFix'...
Hello!
[06:10:37] Finished 'swExcludePathFix' after 4.34 ms
C:\Code\ngtest  (mgmt-console@0.0.0)
λ npm run lint

> mgmt-console@0.0.0 lint C:\Code\ngtest
> ng lint

ERROR: C:/Code/ngtest/src/index.ts:1:13 - " should be '
ERROR: C:/Code/ngtest/src/index.ts:1:30 - file should end with a newline

Lint errors found in the listed files.

All files pass linting.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mgmt-console@0.0.0 lint: `ng lint`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mgmt-console@0.0.0 lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Dioge\AppData\Roaming\npm-cache\_logs\2018-12-30T11_11_20_778Z-debug.log

What you're seeing looks like an issue with npm linked packages. If TypeScript can't resolve @types/node from some path within your node_modules directory, I'm guessing that's why.

Closing this issue as non-reproducible since it looks like it's on your end, but please do ping me on https://gitter.im/palantir/tslint if this doesn't help!

doronsever commented 5 years ago

@JoshuaKGoldberg again, when I downgrade to 5.11.0 everything works fine...

JoshuaKGoldberg commented 5 years ago

@doronsever yes, it's spooky. Maybe it's a linking problem, perhaps with version resolving thrown in there? Maybe some other kind of weird dependency versioning difference? Without more information it's not really possible to help. Gitter is a better chat medium for this kind of support.

Edit: to be more clear for future folks reading this, the issue tracker is normally just for issues (bugs, feature requests, documentation improvements, and the like) in TSLint. 5.12.0 was structurally almost identical to 5.11.0 and other Angular projects are working fine with it, so it's very unlikely this is an issue in TSLint itself. Gitter and StackOverflow are recommended for other requests, such as this mysterious kind of breakage. If you see this too (or otherwise have indication I'm horribly wrong here), please do post and this issue can be re-opened!

cromat commented 5 years ago

I am not sure that this is not tslint error. I have the same problem, version 5.12.0 gives identical errors and 5.11.0 works fine.

I have tried with angular versions 7.12 and 7.1.4 and both don't work with 5.12.0

JoshuaKGoldberg commented 5 years ago

Same request @cromat - can you post a way to reproduce this locally?

cromat commented 5 years ago

As I haven't been able to reproduce error within new angular project (I have tried to copy my orginal package.json file, angular.json, tslint.json), I have found out that error actually comes from application code. I have been digging trough code for some while and found out that project won't build because of function arrayify.

This function is imported from 'tslint/lib/utils' so I am assuming that some other functions imported from here could also cause this problem.

If that still did not fix problem for someone, this error is caused while bundling files for app and lately node config was changed inside webpack from:

node: {
      global: 'window',
      crypto: 'empty',
      module: false,
      clearImmediate: false,
      setImmediate: false
 }

to node: false

and this change was also causing this error.

This guy has made a patch script that monkey-patches this error but it is just quick fix and not recommended for production usage. You can also get more info about this change in same thread.

doronsever commented 5 years ago

@cromat so did you manage to get this fixed? I just pinned it to 5.11.0

cromat commented 5 years ago

Yes. As we have the same error log, you have also probably an import from tslint library. Search yout code for any imports from 'tslint/lib/utils' and remove it or refactor. In my case it was function arrayify that caused problem and that is actually not needed because I could just use plain javasript to make array of some data.

JoshuaKGoldberg commented 5 years ago

@cromat Awesome that you found a fix, thanks! 🙌

But: how does importing from tslint/lib/utils lead to this error? Is it that utils.d.ts has a types dependency on those modules, but isn't explicitly declared in the published dependencies list in tslint/package.json?

cromat commented 5 years ago

@JoshuaKGoldberg I am not sure what causes the problem. I have tried to change build settings because I thought that maybe tslint is not building with other parts of app and then importing something from it breaks the app but seems that this is not the problem. I haven't yet investigated differences between tslint versions 5.11.0 and 5.12.0 to find out what the breaking changes are.

doronsever commented 5 years ago

I can confirm removing all tslint/lib/utlis imports fixed the issue. @JoshuaKGoldberg I would still consider this as a tslint bug since it works fine in 5.11.0

willydee commented 5 years ago

The same problem bit me today. Turned out that there was indeed an erroneous

import { hasOwnProperty } from 'tslint/lib/utils';

in our code. Fixed the code, removed the unnecessary import, et voilà, build runs smoothly.

JoshuaKGoldberg commented 5 years ago

This is really a subset / piece of contextual info for #2446. It's not documented well (accepting pull requests on the docs!) but the lib/subdirectory is not part of the public API. It's only a coincidence that that happens to work well in many scenarios.

@doronsever, I would normally close the issue at this point, but since it's been back & forth a bit - any thoughts?

doronsever commented 5 years ago

Removing the imports fixes this issue.

prudnikov commented 5 years ago

I had the same issue, I was using hasOwnProperty from tslint/lib/utils. Replaced it with Object.prototype.hasOwnProperty and successfully upgraded to 5.13.

JoshuaKGoldberg commented 4 years ago

🤖 Beep boop! 👉 TSLint is deprecated 👈 and you should switch to typescript-eslint! 🤖

🔒 This issue is being locked to prevent further unnecessary discussions. Thank you! 👋