typescript-formatter icon indicating copy to clipboard operation
typescript-formatter copied to clipboard

unable to read tslint, not found.

Open kevin074 opened this issue 6 years ago • 4 comments

I init a tslint via https://palantir.github.io/tslint/ quick start direction Then installed typescript-formatter according to direction on github Finally tried tsfmt -r to test the package, error showed: "Error: Cannot find module 'tslint' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15) at Function.Module._load (internal/modules/cjs/loader.js:507:25) at Module.require (internal/modules/cjs/loader.js:637:17) at require (internal/modules/cjs/helpers.js:20:18) at /usr/local/lib/node_modules/typescript-formatter/lib/provider/tslintjson.js:131:86"

then tried tsfmt -r --no-tslint and the compilation was completed with replacements done.

All commands done at the root directory where tsconfig.json and tslint.json also lives. I have also tried to do the commands in the folder where the TS files lives (but not the .json files), and the same error is shown.

kevin074 avatar Aug 20 '18 22:08 kevin074

if you installed typescript-formatter globally, it also requires tslint globally.

That's a workaround though. In my opinion, if this is the case, tslint should be listed as a dependency of typescript-formatter

stweedie avatar Sep 27 '18 18:09 stweedie

i do have tslint globally though. The quick start directions have listed so and also just checked outside of my project folder with "tslint" command :( anything else you can think of ?

kevin074 avatar Sep 27 '18 19:09 kevin074

sorry for the delay. I'm terrible about checking GH notifications since my current project uses a different site for source control.

Can you try to install both tslint and typescript formatter locally and running it from the node_modules/.bin folder?

also, make sure tsfmt, tsc, and tslint are accessible from path:

tsfmt -v
tslint -v

though I would think they are since they're installed globally. These are just diagnostic steps though. It seems more like a problematic npm / node configuration than anything, since the code just delegates to node's 'require' method to load tslint.

I'm definitely curious though. Can you list all global packages you have installed, as well as the dependencies from your project? (obviously you can omit anything private / personal) I'll try and recreate your installation and see if I can repro

stweedie avatar Oct 11 '18 15:10 stweedie

OMG thanks!!

I did the local installation and it worked fine, which was strange to me. So then I found that you could npm install -g tslint instead of yarn global add tslint.

for some reason installing through npm allowed tsfmt to find tslint now. How weird if you know anything about why please let me know.

I think the documentation on this github should update about this. Cause on the tslint website it said to use yarn. Although I understand that most people probably would have just npm install -g tslint without thinking ... lol

kevin074 avatar Oct 22 '18 19:10 kevin074