Skip to content

Not detecting tsconfig.json (Sublime Text 3) #213

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

Closed
robertdp opened this issue Jun 5, 2015 · 27 comments
Closed

Not detecting tsconfig.json (Sublime Text 3) #213

robertdp opened this issue Jun 5, 2015 · 27 comments

Comments

@robertdp
Copy link

robertdp commented Jun 5, 2015

I have the file ./tsconfig.json in the root folder of the project, with "modules": "commonjs" set correctly.

When editing any file 2 or more folders deep (e.g. ./src/journal/module.ts), TypeScript reports an error for every import and export statement:

Cannot compile modules unless the '--module' flag is provided

This error doesn't show up for files under ./src, and there are no module/import errors when building the project.

Also mentioned in #207.

@LPGhatguy
Copy link

This is also reported in issue #180, which is marked as resolved.

@zhengbli zhengbli added the Bug label Jun 5, 2015
@zhengbli
Copy link
Contributor

zhengbli commented Jun 5, 2015

The problem is that currently the server seems only search for two levels of directory, therefore when it goes deeper than that it cannot find the config file. Working on a fix.
I actually failed to reproduce the problem on both windows and mac. My folder structure is as follows:
file1: "./src/modules/deeperModule/deeperAgainModule/test.ts", content:

import {g} from 'test1';

file2: "./src/modules/deeperModule/deeperAgainModule/test1.ts", content:

export var g = 0;

tsconfig.json content:

{
    "compilerOptions": {
        "module": "commonjs"
    },
    "files": [
        "./src/modules/deeperModule/deeperAgainModule/test.ts",
        "./src/modules/deeperModule/deeperAgainModule/test1.ts"
    ]
}

I can get intellisense for g fine in test.ts. So could you tell more about your structure? How is it different from my setup? Mine is pretty rudimentary that may have ruled out some other factors.

@LPGhatguy The issue in #180 is different though. That one was caused by changes in the tsserver.js file that leads to the missing config file, even in the same directory.

@corruptmem
Copy link

I'm also experiencing the same problem. I'll try to see if I can get more information about why.

@LPGhatguy
Copy link

I'm actually experiencing this issue too, and my path to my entrypoint is one/two/three/scripts/main.ts, with my deepest paths being one/two/three/scripts/Components/Core/component.ts. I get intellisense just fine, and I only get import/export errors sometimes, and I can't seem to reproduce when that happens.

@zhengbli
Copy link
Contributor

The reason is that currently we don't have a file watcher for tsconfig.json, therefore you have to restart sublime to apply your changes

From: Lucien Greathouse [email protected]
Sent: Jul 21, 2015 10:16 AM
To: Microsoft/TypeScript-Sublime-Plugin
Cc: Zhengbo Li
Subject: Re: [TypeScript-Sublime-Plugin] Not detecting tsconfig.json (Sublime Text 3) (#213)

I'm actually experiencing this issue too, and my path to my entrypoint is one/two/three/scripts/main.ts, with my deepest paths being one/two/three/scripts/Components/Core/component.ts. I get intellisense just fine, and I only get import/export errors sometimes, and I can't seem to reproduce when that happens.

Reply to this email directly or view it on GitHubhttps://github.com//issues/213#issuecomment-123406494.

@LPGhatguy
Copy link

I just opened my project fresh today (I just got to work) and I'm getting the same errors on one of my files -- I haven't changed tsconfig.json in a week or so and I just opened Sublime Text fresh.

@zhengbli
Copy link
Contributor

@LPGhatguy Can you paste the content of your tsconfig.json file? Or do you see any error if you directly run tsc from the command line in the folder?

@LPGhatguy
Copy link

I'm just using this file. I don't specify any files; is that a problem?

{
    "compilerOptions": {
        "module": "commonjs",
        "detectGlobals": false
    }
}

@zhengbli
Copy link
Contributor

@LPGhatguy When I run tsc directly from the commandline, I got the error:

error TS5023: Unknown compiler option 'detectGlobals'.

It seems your tsconfig file is not valid

@LPGhatguy
Copy link

That could be the issue; that was an option I was passing through to a gulp TypeScript transpilation plugin. I'll let you know if I see the issue again with that config.

@teintinu
Copy link

I'm experiencing the same problem, but sometimes works sometimes not works.
I think this bug is in tsserver because I edited typescript/commands/build.py with

    print(project_info)

and body was empty

{'seq': 0, 
  'command': 'projectInfo', 
  'type': 'response', 
  'body': {}, 
  'request_seq': 7, 
  'success': True
}

I dont know how tsserver works, someone can help me?

@LPGhatguy
Copy link

I hit the issue again after refactoring my typing files to be inputs to the compiler instead of /// reference directives

@breezewish
Copy link

I have the same issue here.

If my tsconfig.json doesn't contain files, or contain files and the current file name is in the list, the tsconfig.json path is resolved correctly in typescript/commands/build.py. Otherwise (contain files array but the current file name is not in the array), the body is empty:

{'success': True, 'request_seq': 22, 'type': 'response', 'seq': 0, 'command': 'projectInfo', 'body': {}}

@tomachristian
Copy link

Execute

npm install typescript

in the root folder, this will install the latest TypeScript compiler and should work.

@prijkes
Copy link

prijkes commented Feb 6, 2016

I had the same problem; I would get the error no matter where I would place a .ts file.
After analyzing what happened, I realized that the TypeScript-Sublime-Plugin uses it's own internal tsserver.js installed with it. The problem was that it wasn't the same version as the typescript that I had installed globally from npm. Since the global typescript tsserver.js wasn't used for checking .ts files, it would give me the same error:

Cannot compile modules unless the '--module' flag is provided

but running tsc on the command-line would not. This is because the tsserver.js from TypeScript-Sublime-Plugin doesn't recognize some options in the tsconfig.json, like emitDecoratorMetadata for example.

TL;DR
The solution is to set the 'typescript_proc_file' settings in your sublime-settings file (Preferences -> Settings - User) to the globally installed tsserver.js file.
In my case:
"typescript_proc_file": "C:/Users/admin/AppData/Roaming/npm/node_modules/typescript/lib/tsserver.js"
You have to restart sublime for the changes to take effect.

@billti
Copy link
Member

billti commented Feb 6, 2016

@summerwish That behavior sounds correct. If you are listing the files explicitly in the tsconfig.json, and the current file isn't one of them (or included/imported by one of them), then the current files isn't going to use that tsconfig.json. It's going to get its own context.

@NeWbY100 Correct. The Sublime plugin ships its own version of tsserver.js, so if you want to use a specific version (i.e. one which may have features or behavior you depend on), then that needs to be specified.

With these two issues, and the prior issue of an invalid compilerOption, that seems to be all the root causes of this issue. I'll close now, comment for further investigation if there are further causes not covered. Thanks!

@billti billti closed this as completed Feb 6, 2016
@NekR
Copy link

NekR commented Mar 23, 2016

So why this is closed? TS plugin doesn't see my tsconfig.json for a new project. Yes, I reloaded sublime already.

It doesn't see d.ts files in files section. Also it reports that I have to use es6 target for es6 features, but I already specified that.

@NekR
Copy link

NekR commented Mar 23, 2016

What about manually specifying path to tsconfig.json for a projects (my tsconfig.json is in the root)?

@NekR
Copy link

NekR commented Mar 23, 2016

Or some debug UI to find tsconfig.json or possible errors? Because webpack TS loader correctly finds and uses tsconfig.json.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 23, 2016

@NekR, can you share a sample we can look at?

@garkbit
Copy link

garkbit commented Mar 30, 2016

Echoing what @NekR is saying, I've tried the things mentioned above. tsc is quite happy with my tsconfig.json file, I've added the typescript_proc_file setting, and still no usage of my tsconfig.json file. I'm at a loss even for what to provide for diagnostic purposes.

@garkbit
Copy link

garkbit commented Mar 30, 2016

OK, so I manually downgraded the plugin to v0.1.1, and it correctly picks up tsconfig.json. The issue was introduced with v0.1.2.

@garkbit
Copy link

garkbit commented Mar 30, 2016

All right, I've resolved this. It was apparently basically the same issue face by @NeWbY100, however, the property that needed to be set has subsequently changed. Whereas @NeWbY100 set the following:

"typescript_proc_file": "/path/to/typescript/lib/tsserver.js"

The property and usage have now changed to:

"typescript_tsdk": "/path/to/typescript/lib"

Note the absence of tsserver.js. It's now used to figure out which tsserver.js and tsc.js to use.

@NekR, I'd give this a shot and see if it works.

@NekR
Copy link

NekR commented Mar 31, 2016

@garkbit thanks for info, I will try it today or so.
@mhegazy sorry for not providing more info, missed your comment.

@johndeighan
Copy link

I'm having a similar problem with a default installation of Sublime Text 3. I'm learning Angular 2. To set up a new project, I'm using angular-cli like this:


ng new angular2_hello_world

which sets up this directory structure:

angular2_hello_world/
   src/
      app/
         app.component.ts
         ...other files
      index.html
      tsconfig.json
      ...other files

That is, my tsconfig.json is in the src/ folder, but outside the app/ folder. My source file, app.component.ts in in the app/ folder. When I open the source file, I see this error:

Experimental support for decorators is a feature that is subject to change in a future release.
Set the 'experimentalDecorators' option to remove this warning.

But that option is set to true in the tsconfig.json file, so I have to assume that my tsconfig.json is not being used.

If it matters, I was cd's to the enclosing angular2_hello_world/ folder when I entered the command 'subl .'.

Since this is the default directory structure created by angular-cli and I'm using a clean install of Sublime Text 3 (Build 3126), it seems to me that a lot of folks will run into this problem in the future. The web site builds and runs just fine - I'm not using Sublime Text 3 to build and run - but I'd really like that warning to go away and anticipate problems with other settings in the future if I can't get the Sublime TypeScript plug-in to use my tsconfig.json file.

@fiznool
Copy link

fiznool commented Nov 17, 2016

@johndeighan I think this is related to #542

@Quasso
Copy link

Quasso commented Nov 17, 2016

+1 @johndeighan, I've been experiencing that exact problem recently (notably, sporadically)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests