0

Simple problem, in WebStorm:

@Component moduleId: module.id tslint error: Corresponding file is not included in tsconfig.json

In addition to that, tsc complains with:

error TS2304: Cannot find name 'module'.

I'm looking either:

  1. For something like jshint's "predef" key that allows you to ignore global variables that are defined above the scope of the active inspection, or
  2. To add some annotation or import to my @Component that I have forgotten to allow TSLint to see module, which comes from SystemJS.

Importantly, I do not want to add in-code //noinspection TypeScriptUnresolvedVariable because this moduleId: module.id pattern is well-known for Angular2 and required in every single component we have. It doesn't look like something that should be ignored systemically.

I noticed that TSLint has an ignore-pattern directive, but it's a subset of no-unused-variable, which is not what I'm looking for.

I'm using WebStorm 2016.2.4 with TSLint 2 locally. Here is my tsconfig.json:

{
  "version": "2.0.3",
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "dist",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "module": "system",
    "moduleResolution": "node",
    "removeComments": true,
    "sourceMap": true,
    "noImplicitAny": true,
    "allowSyntheticDefaultImports": true
  },
  "typeRoots": [ "node_modules/@types" ],
  "filesGlob": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

I have also tried

"compilerOptions" {
  "target": "es5",
  "module: "commonjs",
  ... }

To no avail.

Community
  • 1
  • 1
msanford
  • 11,803
  • 11
  • 66
  • 93
  • Did you install @types/node? – pe8ter Oct 28 '16 at 14:55
  • @pe8ter Good question! Yes, but that's another problem. I have indeed `npm i "@types/node"` but tsc also _always_ complains with `node_modules/@types/node/index.d.ts(283,40): error TS1110: Type expected.`, though it seems unrelated. – msanford Oct 28 '16 at 15:06
  • A few things look off in your tsconfig.json: typeRoots belongs in compilerOptions and "filesGlob" should be renamed to "include". http://www.typescriptlang.org/docs/handbook/tsconfig-json.html – pe8ter Oct 28 '16 at 15:48
  • Are you using WebStorm's bundled TypeScript compiler? 2016.2.4 comes with TypeScript compiler version 1.8.10. You need to point it at a newer version. – pe8ter Oct 28 '16 at 15:53
  • @pe8ter I am indeed using TS2 (I pointed the Custom TypeScript location to my `node_modules/typescript/lib/` folder). – msanford Oct 28 '16 at 17:29
  • Could you try `./node_modules/typescript/bin/tsc -v`. The error "Type expected" at line 283 is for a nullable type, which is only available in TS 2. That suggests you're still using TS 1.x. – pe8ter Oct 28 '16 at 21:34
  • It went away of its own accord, for whatever reason. Thank you all for your help! – msanford Jan 04 '17 at 19:50

1 Answers1

0

I suppose it was caused by something transient, as I have not seen it for weeks.

msanford
  • 11,803
  • 11
  • 66
  • 93