Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can TypeScript be installed globally? #2041

Closed
iwis opened this issue May 18, 2020 · 2 comments
Closed

Can TypeScript be installed globally? #2041

iwis opened this issue May 18, 2020 · 2 comments
Labels
working as intended Issues that are closed as they are working as intended

Comments

@iwis
Copy link
Contributor

iwis commented May 18, 2020

Several months ago I installed TypeScript globally by running: npm install - g typescript
Today I made steps described on https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/README.md i.e.:

  1. I run: yarn add -D eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin

The result was:

...
info No lockfile found.
...
warning "@typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
warning " > @typescript-eslint/parser@2.34.0" has incorrect peer dependency "eslint@^5.0.0 || ^6.0.0".
warning " > @typescript-eslint/eslint-plugin@2.34.0" has incorrect peer dependency "eslint@^5.0.0 || ^6.0.0".
...
success Saved lockfile.
success Saved 104 new dependencies.
...
  1. I created .eslintrc.js file with the content given in README.md.

  2. I run: yarn eslint . --ext .js,.jsx,.ts,.tsx
    The result was:

Oops! Something went wrong! :(

ESLint: 7.0.0

Error: Failed to load plugin '@typescript-eslint' declared in '.eslintrc.js': Cannot find module 'typescript'
Require stack:
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\tsutils\typeguard\2.8\node.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\tsutils\typeguard\2.9\node.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\tsutils\typeguard\3.0\node.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\tsutils\typeguard\3.2\node.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\tsutils\typeguard\node.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\tsutils\typeguard\index.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\tsutils\index.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\@typescript-eslint\eslint-plugin\dist\util\isTypeReadonly.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\@typescript-eslint\eslint-plugin\dist\util\index.js   
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\@typescript-eslint\eslint-plugin\dist\rules\adjacent-overload-signatures.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\@typescript-eslint\eslint-plugin\dist\rules\index.js  
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\@typescript-eslint\eslint-plugin\dist\index.js        
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\eslint\lib\cli-engine\config-array-factory.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\eslint\lib\cli-engine\cascading-config-array-factory.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\eslint\lib\cli-engine\cli-engine.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\eslint\lib\eslint\eslint.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\eslint\lib\eslint\index.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\eslint\lib\cli.js
- C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\eslint\bin\eslint.js
Referenced from: C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\.eslintrc.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:772:15)
    at Function.Module._load (internal/modules/cjs/loader.js:677:27)
    at Module.require (internal/modules/cjs/loader.js:830:19)
    at require (C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
    at Object.<anonymous> (C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\tsutils\typeguard\2.8\node.js:3:12)
    at Module._compile (C:\Users\Darek\Documents\Inne\Notatki\1.Programowanie\2.6.JavaScript\Browser\iw-components\node_modules\v8-compile-cache\v8-compile-cache.js:194:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
    at Module.load (internal/modules/cjs/loader.js:790:32)
    at Function.Module._load (internal/modules/cjs/loader.js:703:12)
    at Module.require (internal/modules/cjs/loader.js:830:19)
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I uninstalled global TypeScript by npm uninstall - g typescript, then installed it locally by npm install typescript, and finally I performed the above mentioned steps 1, 2 and 3. Now ESlint works.
Unfortunately I have not found information that TypeScript should not be installed globally. If this is really the case, then please add this information to README.md.

@bradzacher bradzacher added the working as intended Issues that are closed as they are working as intended label May 18, 2020
@bradzacher
Copy link
Member

bradzacher commented May 18, 2020

I believe you're making the incorrect assumption about the npm ecosystem.
You should assume that a tool will not work with global installs unless specifically stated in the readme.
Global installs often require extra work from the package author to support properly.

Particularly in the case of requiring dependencies in a global package space vs a local package space - a package author needs to specifically and consciously setup their requires such that they check both the local and global spaces, which almost no packages do.

You must install our tooling and all of the required dependencies locally for it to work.
We do not support global typescript installs, and likely never will.

@iwis
Copy link
Contributor Author

iwis commented May 18, 2020

I made a pull request #2043 to add information about this to FAQ.md. I added a justification why the information can be important. I am a new npm user, so maybe only I have such problems. In this case, feel free to delete the pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
working as intended Issues that are closed as they are working as intended
Projects
None yet
Development

No branches or pull requests

2 participants