Tslint: Cannot find module 'typescript'

Created on 12 Apr 2018  路  1Comment  路  Source: palantir/tslint

Bug Report

  • __TSLint version__: 5.9.1
  • __TypeScript version__: 2.8.1 (global installed)
  • __Running TSLint via__: VSCode銆丆LI

tslint.yaml configuration

extends:
  - 'tslint:latest'
  - tslint-eslint-rules
  - tslint-config-prettier
defaultSeverity: error
rulesDirectory: tslint-plugin-prettier
rules:
  prettier: true
  max-line-length:
    options:
      - 120
  no-constant-condition: true
  trailing-comma: false
  object-literal-sort-keys: false
  ordered-imports: false
  no-console: false
  no-unused-expression:
    - true
    - allow-fast-null-checks

package.json configuration

...
"scripts": {
    "lint": "tslint -c tslint.yaml '*.ts?(x)'; exit 0",
}
...

Execute command

yarn lint

Actual behavior

yarn run v1.5.1
$ tslint -c tslint.yaml '*.ts?(x)'; exit 0
module.js:545
    throw err;
    ^

Error: Cannot find module 'typescript'
    at Function.Module._resolveFilename (module.js:543:15)
    at Function.Module._load (module.js:470:25)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (xxx/node_modules/tslint/lib/linter.js:22:10)
    at Module._compile (module.js:649:30)
    at Object.Module._extensions..js (module.js:660:10)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)

The xxx/node_modules/tslint/lib/linter.js:22:10 :

...
var ts = require("typescript");
...

Expected behavior

Lint the ts files.

Temporary Solutions

When I install the typescript locally, it works.

Does typescript can't be installed globally?

Most helpful comment

Hey, according to this SO post: https://stackoverflow.com/questions/15636367/nodejs-require-a-global-module-package, it looks like locally installed modules don't look for modules from the global module directory.

I think that you can install both tslint/typescript locally or globally, but not mixed.

>All comments

Hey, according to this SO post: https://stackoverflow.com/questions/15636367/nodejs-require-a-global-module-package, it looks like locally installed modules don't look for modules from the global module directory.

I think that you can install both tslint/typescript locally or globally, but not mixed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cateyes99 picture cateyes99  路  3Comments

ghost picture ghost  路  3Comments

SwintDC picture SwintDC  路  3Comments

mrand01 picture mrand01  路  3Comments

ghost picture ghost  路  3Comments