Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Cannot start tslint with npm script #1664

Closed
bertolo1988 opened this issue Oct 31, 2016 · 20 comments
Closed

Cannot start tslint with npm script #1664

bertolo1988 opened this issue Oct 31, 2016 · 20 comments

Comments

@bertolo1988
Copy link

bertolo1988 commented Oct 31, 2016

Bug Report

  • TSLint version: 3.15.1
  • TypeScript version: 2.0.6
  • Running TSLint via: npm script

If i type `tslint --project .' it works:

...
src/core/app.ts[1, 33]: ' should be "
src/core/app.ts[3, 26]: ' should be "
src/core/app.ts[4, 27]: ' should be "
src/core/app.ts[5, 29]: ' should be "
src/core/app.ts[7, 21]: ' should be "
src/core/app.ts[7, 30]: ' should be "
src/core/app.ts[27, 22]: ' should be "
src/core/app.ts[28, 23]: ' should be "
src/core/app.ts[1, 62]: Missing semicolon
src/core/app.ts[3, 35]: Missing semicolon
src/core/app.ts[4, 37]: Missing semicolon
src/server.ts[1, 21]: ' should be "
src/server.ts[2, 17]: ' should be "
src/server.ts[1, 33]: Missing semicolon

If i run the same command with an npm script i get:

me@me-ubu-N3355SL:~/project/server$ npm run lint

> server@1.0.0 lint /project/server
> tslint --project '.'

Usage: /usr/bin/nodejs ./node_modules/.bin/tslint [options] [file ...]

Options:
  -c, --config          configuration file                                                      
  -h, --help            display detailed help                                                   
  -i, --init            generate a tslint.json config file in the current working directory     
  -o, --out             output file                                                             
  -r, --rules-dir       rules directory                                                         
  -s, --formatters-dir  formatters directory                                                    
  -e, --exclude         exclude globs from path expansion                                       
  -t, --format          output format (prose, json, verbose)                                      [default: "prose"]
  --test                test that tslint produces the correct output for the specified directory
  -v, --version         current version                                                         

Missing files

npm ERR! Linux 4.8.0-26-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "lint"
npm ERR! node v6.9.1
npm ERR! npm  v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! server@1.0.0 lint: `tslint --project '.'`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the server@1.0.0 lint script 'tslint --project '.''.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the server package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     tslint --project '.'
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs server
npm ERR! Or if that isn't available, you can get their i...

And this is what i get in my npm-debug.log

13 info lifecycle server@1.0.0~lint: Failed to exec lint script
14 verbose stack Error: server@1.0.0 lint: `tslint --project '.'`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/lib/utils/lifecycle.js:255:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:191:7)
14 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:191:7)
14 verbose stack     at maybeClose (internal/child_process.js:877:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
@bertolo1988 bertolo1988 changed the title cant start tslint with npm script Cannot start tslint with npm script Oct 31, 2016
@nchen63
Copy link
Contributor

nchen63 commented Nov 4, 2016

can you try running tslint --project '.' on the command line?
try editing your package.json file to not use the single quotes?
does it work with an absolute path?

@bertolo1988
Copy link
Author

bertolo1988 commented Nov 4, 2016

tslint --project '.' works on the command line.
"lint": "tslint --project .", this and "lint": "tslint --project '.'", do not work using npm run lint

I have used pwd to determine the fullpath of my project and also tried:
npm run lint with lint script as "lint": "tslint --project fullpath/", and it did not work either.

@nchen63
Copy link
Contributor

nchen63 commented Nov 6, 2016

I just noticed that the help text doesn't include --project. You're running an old version of tslint when running with npm, which doesn't support that option. I'm guessing that you have one version installed globally and a different one in node_modules

@bertolo1988
Copy link
Author

bertolo1988 commented Nov 14, 2016

@nchen63 I confirmed that it was not the case.

Found something new and it was very odd

root@.../.../...# npm install typescript -g
/usr/bin/tsc -> /usr/lib/node_modules/typescript/bin/tsc
/usr/bin/tsserver -> /usr/lib/node_modules/typescript/bin/tsserver
/usr/lib
└── typescript@2.0.9 

root@.../.../...# npm install -g tslint
/usr/bin/tslint -> /usr/lib/node_modules/tslint/bin/tslint
/usr/lib
├── tslint@3.15.1 
└── UNMET PEER DEPENDENCY typescript@>=1.7.3

@adidahiya
Copy link
Contributor

@bertolo1988 that looks like #1003

@nchen63
Copy link
Contributor

nchen63 commented Nov 14, 2016

@bertolo1988 Try changing your lint script to npm -v and see what version it says

@bertolo1988
Copy link
Author

bertolo1988 commented Nov 14, 2016

@nchen63

npm run lint
> npm -v

gives: 3.10.8, same as npm -v

Notice that people with #1003 can still use tslint...i can't.

@nchen63
Copy link
Contributor

nchen63 commented Nov 15, 2016

the reason I ask is because you listed 3.15.1 in your bug report. the --project flag was introduced in 3.14.0

@nchen63
Copy link
Contributor

nchen63 commented Nov 15, 2016

ah, sorry, can you run tslint -v, not npm -v in your script

@bertolo1988
Copy link
Author

3.15.1

@nchen63
Copy link
Contributor

nchen63 commented Nov 15, 2016

well, I don't know what to say. Your help text does not give the --project option, so something is wrong with the version

@IllusionMH
Copy link
Contributor

Haven't seen such problem, but I can guess only next options to try at first:

  1. Globally you have 3.15.1 but local version is lower that 3.14.0 (npm scripts prepend your local node_modules folder to PATH variable, so there can be differences).
    • To make sure that local is ok try ./node_modules/.bin/tslint -v and ./node_modules/.bin/tslint --project "." in console.
  2. Try double quotes ("lint": "tslint --project \".\"" ) instead of single quotes in npm scripts.
  3. Try "lint": "tslint --project \"tsconfig.json\"" in npm scripts.
  4. Try to install latest dev version of TSLint
    • Remove node modules
    • npm i typescript@2 tslint@next
    • Update npm script to "lint": "tslint --project \".\""
      npm run lint

@bertolo1988
Copy link
Author

bertolo1988 commented Nov 16, 2016

I removed my global installation. Now i cannot run tslint on my console. I installed it locally and the version inside is "_id": "tslint@3.15.1",.

If i try to run tslint -v on my console it fails. That is ok i am expecting this since i dont have it globally installed.

If i set a npm script such as "lint":"npm -v" i get:

me@me-ubu-N55SL:~/path/sticky-notes$ npm run lint
sticky-notes@0.0.1 lint /path/sticky-notes
tslint -v
3.15.1

I think that only the global installation should allow me to run tslint. Installed as a npm module, it would only be accessible by using require/import.

IMPORTANT: Running tslint globally works well, when installed locally and running as an npm script i get this error

@IllusionMH
Copy link
Contributor

@bertolo1988 does it works as expected now?
If yes - glad that your problem is solved.

@bertolo1988
Copy link
Author

bertolo1988 commented Nov 16, 2016

@IllusionMH No wait. i "isolated" the problem a bit better. There is a problem still. Check my previous comment.

@IllusionMH
Copy link
Contributor

@bertolo1988 if I understand correctly - you've managed to install 3.15.1 to the project (which was root case for problem with --project flag).
I've checked link with log output from your previous comment and everything is works as expected.

In short - this is just NPM detailed reaction on exit code when there are lint errors.
For more details and options check this thread #1704

P.S. To be sure that you run same package version as your build tools and CI - I personally prefer to use npm scripts or use packages from local installations like ./node_modules/.bin/tslint --project "." in your case

@bertolo1988
Copy link
Author

bertolo1988 commented Nov 16, 2016

I just confirmed that if there are no lint errors, it ends the execution just fine.

I think that you should place a big warning in the repo readme for this because most of people will most likely run tslint with a npm script and get confused with the errors, just like me.

Thanks alot for your help. ;)

@nchen63 nchen63 closed this as completed Nov 16, 2016
@slavafomin
Copy link

Just spent half an hour fighting this issue. You should really add the warning somewhere about this use case, cause it's really a standard now to call such scripts using npm run ....

@jamesroseman
Copy link

jamesroseman commented Sep 15, 2017

Just ran into this issue and had to dig this up, posting for posterity. I personally didn't like my npm script failing when the linting failed, so I made this adjustment:

"lint:be": "./node_modules/.bin/tslint --project 'server' -t stylish || echo",

As written, this will never fail. Use with caution. I just personally couldn't stand the huge NPM error messages.

Alternatively, using yarn instead of npm also "fixes" this issue.

"lint": "yarn run lint:be",
"lint:be": "./node_modules/.bin/tslint --project 'server' -t stylish",

adamcee added a commit to adamcee/shuttle_code that referenced this issue Feb 15, 2018
…f its locally installed.

- add script to run tslint, add a bit of cleanup to script to deal with annoying npm error message which shows up if there are linting errors:
palantir/tslint#1664 (comment)
	modified:   package.json
samtux added a commit to samtux/kitematic that referenced this issue Jul 4, 2018
@JoshuaKGoldberg
Copy link
Contributor

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

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

@palantir palantir locked and limited conversation to collaborators Sep 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants