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

Invalid module name in augmentation #8518

Closed
wizardnet972 opened this issue May 8, 2016 · 114 comments
Closed

Invalid module name in augmentation #8518

wizardnet972 opened this issue May 8, 2016 · 114 comments
Labels
Duplicate An existing issue was already created

Comments

@wizardnet972
Copy link

Hi,

In visual studio, i got this error in every d.ts file under node_modules\rxjs\add\observable\ :
Invalid module name in augmentation, module '../../Observable' cannot be found.
example code: declare module '../../Observable' {

how to fix that please?

@mhegazy
Copy link
Contributor

mhegazy commented May 8, 2016

can you share a sample project we can look at?

@mhegazy mhegazy added the Needs More Info The issue still hasn't been fully clarified label May 8, 2016
@wizardnet972
Copy link
Author

did visual studio 2015 uses latest typescript release?
Rxjs 5 uses module augumentation introduced at 1.8 (https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#augmenting-globalmodule-scope-from-modules )
?

@pantonis
Copy link

pantonis commented May 9, 2016

Same problem here.

@ghost
Copy link

ghost commented May 9, 2016

Same here, "rxjs": "5.0.0-beta.6" as well as beta.7
VS 2015 with Update 2 and all installed updates.
TS version is of course >1.8

@bcrigler
Copy link

bcrigler commented May 9, 2016

Installed the latest 1.8.6 download from Microsoft as a VS extension experiencing the same issue...

How do I point Visual Studio to use the local version of Typescript installed locally within my project? (which I have 1.8.10 installed locally)

@ghost
Copy link

ghost commented May 9, 2016

@bcrigler no way to point VS to use local TypeScript compiler. We have to wait next extention update.
Or you can separate your web project into VS Code project + Service project for C# logic and use local TS with VS code.

@mhegazy
Copy link
Contributor

mhegazy commented May 9, 2016

Do not do this if you have Update 3 RTM installed

I see the issue now. this is a duplicate of #7415, and should be fixed in the next release (see #7507).

As work arounds for now, you can replace C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TypeScript\typescriptServices.js with the file in https://raw.githubusercontent.com/Microsoft/TypeScript/Fix8518/lib/typescriptServices.js. First take a local backup though.

@mhegazy mhegazy added Duplicate An existing issue was already created and removed Needs More Info The issue still hasn't been fully clarified labels May 9, 2016
@giancarloa
Copy link

Hi there @mhegazy ... I tried your suggestion... but now when I try to open the project I get the error "API version mismatch: manager version 0.4, script version 0.5"... any ideas? thanks

tserr
"

@mhegazy
Copy link
Contributor

mhegazy commented May 9, 2016

What version of VS are you using? update 2?

@giancarloa
Copy link

@mhegazy ... no i am using update1... i guess i should be using update 2 correct???

@mhegazy
Copy link
Contributor

mhegazy commented May 9, 2016

correct.

@bcrigler
Copy link

bcrigler commented May 9, 2016

Got it working with the "workaround". Thank you @mhegazy !!!

@ZenSoftware
Copy link

@mhegazy This fixed the problem for me ^_^

@BobbyTable
Copy link

BobbyTable commented May 11, 2016

Can confirm, solution by @mhegazy works with rxjs 5.0.0-beta.6

@mcanic
Copy link

mcanic commented May 17, 2016

+1 conformed, solution of @mhegazy works, except for that I had to modify node_modules\typescript\lib\typescriptServices.js under my project folder instead of C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TypeScript\typescriptServices.js.

Is this a typescript bug then? If so, will it be fixed in the next version, and is this the right fix?

@ghost
Copy link

ghost commented May 17, 2016

@mcanic I've got it working under C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TypeScript\typescriptServices.js.
It's not a bug, it's a missing feature in current VS tools version.

@mcanic
Copy link

mcanic commented May 17, 2016

I'm sure you are right, because I saw that the tsc command compiled fine, but I don't get how this can be a missing feature in the current VS tools version?

Update: of course: it is not typescript, it IS the VS extension itself where the fix was applied, I get it now.
Should we report this bug somewhere?

@mhegazy
Copy link
Contributor

mhegazy commented May 17, 2016

this is a duplicate of #7415, and should be fixed in the next release (see #7507).

@acostaf
Copy link

acostaf commented May 31, 2016

Hi @mhegazy it is possible to refresh VS2013 in order to apply the same fix ?

@mhegazy
Copy link
Contributor

mhegazy commented May 31, 2016

you can use the same steps in #8518 (comment) for VS 2013, the location would be C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TypeScript\typescriptServices.js (12.0 instead of 14.0 in the path).

@acostaf
Copy link

acostaf commented May 31, 2016

Doesn't work, I've got the API error so have to rolled it back, I've am on the latest service pack

@ghost
Copy link

ghost commented Sep 29, 2016

@mhegazy
Windows 8.1 Enterprise
Typescript 2.0.3.0

@TsengSR
Copy link

TsengSR commented Sep 29, 2016

@tylerjgarland: Had similar issue. After uninstalling it and reinstalling it, even code highlighting or formatting would work, not even with 1.8 Version. So I installed the tools and ran npm install -g typescript@2.0 and after a Visual Studio restart it started working again.

If that doesn't work delete the file in the visual studio folder that was replaced in the steps above, do a Visual Studio repair (not TypeScript), the install TypeScript and if still necessary, repeat the step above

@ghost
Copy link

ghost commented Sep 29, 2016

Thanks, @TsengSR I'll give that a shot and report back. I tried just install typescript@2.0 but same Issue. I'll do a repair.

@ghost
Copy link

ghost commented Sep 29, 2016

@TsengSR , @mhegazy It didn't work. I deleted the files. Repaired VS 2015. Installed 2.0.3.0. Ran npm install -g typescript@2.0. Still nothing.

@ghost
Copy link

ghost commented Sep 29, 2016

I updated gulp-typescript to 3.0.1 and typescript 2.0.1 in my package.json. Ran a typescript build using gulp and then intellisense started working. I'm not actually sure what fixed it. Hell, it could be just keeping it open for a while too. I have to upgrade the other devs though so if anyone has clarity on how that fixed my issues, I'd be very thankful.

@viscousbiscuit
Copy link

I had the same problem. I ended up going to programs and feature and uninstalled all previous versions of TypeScript Tools for Microsoft Visual studio, then I installed the latest version of TypeScript tools version 2.X https://www.microsoft.com/en-us/download/details.aspx?id=48593 and this fixed the problem.

@derekmt12
Copy link

This issue would have been a deal-breaker for using Angular 2 on my new project at work. Thanks @Oncidium. That did the trick.

@ghost
Copy link

ghost commented Oct 5, 2016

@Oncidium ,I was using the built-in version for update 3 which I believe was 1.8.6 so there was nothing to uninstall.

@viscousbiscuit
Copy link

viscousbiscuit commented Oct 5, 2016

@tylerjgarland As far as uninstalling, I figure you can never be too careful with these things. What fixed my problem is actually installing Visual Studio's TypeScript tools 2.0.

@ghost
Copy link

ghost commented Oct 7, 2016

So I have a workaround but it's obnoxious. If I type the correct import statement, save it, and restart visual studio it seems the intellisense cache is rebuilt and it works.

@Neilski
Copy link

Neilski commented Oct 14, 2016

vs-angular-error

This is my environment:

  • Visual Studio Professional 2015 Version 14.0.25431.01 Update 3
  • JetBrains ReSharper Ultimate 2016.2.2 (current)
  • TypeScript Version 2.0.3
  • NPM Version 3.10.9

I have the following test project...

  1. /node_modules - generated by npm
  2. /tsScripts - which contains the tsconfig.json file - see below
  3. /tsScripts/App1 - which contains the TypeScript files for my application
// tsconfig.json
{
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "module": "commonjs",
    "noEmitOnError": true,
    "noImplicitAny": false,
    "outDir": "./",
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "moduleResolution": "node"
  },
  "exclude": [
    "node_modules",
    "libs",
    "typings/index",
    "typings/index.d.ts"
  ]
}

When editing a .ts file in /tsScripts/App1, the import { NgModule} from '@angular/core'; shows the intellisense error Cannot find module '@angular/core' (for example). The folder structure /node_modules/@angular/core exists.

The .ts files compile and the project runs successfully without compile-time warnings or errors, perhaps suggesting this is a Visual Studio tooling problem rather than a core TypeScript issue(?)

To try and resolve this problem I have...

  • uninstalled (with manual cleanup) and re-nstalled TS 2.0.3
  • Tried running npm install -g typescript@2

But still the problem exists.

Any suggestions on what I can try next?

UPDATE

In the end, the following fixed it for me:

  1. Go to Tools -> Options -> Text Editor -> TypeScript -> Project -> General
  2. Tick "Automatically compile TypeScript files which are not part of a project"
  3. Select "Use CommonJS code generation for modules

@ghost
Copy link

ghost commented Oct 14, 2016

@Neilski , have you tried unloading and reloading the project. Sometimes you have to prime intellisense. I also benefited from enabling this option.

image

@Neilski
Copy link

Neilski commented Oct 15, 2016

@tylerjgarland , I'd pretty much tried everything and had got into the habit of actually exiting Visual Studio and, fairly regularly rebooting the whole PC (ain't SSDs great?), but nothing worked until I played around with VS's TypeScript options as described above, and immediately everything started to work.

Thinking about it, I guess this makes sense, as the NPM imported/generated code was not included in the project, but it did seem odd that this fix was better/more prolifically mentioned in the posts that I had looked at.

For reference, this is what fixed it for me (which is in alignment with my tscconfig.json settings)...

typescript-options

@mhegazy
Copy link
Contributor

mhegazy commented Oct 17, 2016

@Neilski these changes should have no impact if you have a tsconfig.json. i would say you are running into a different issue. Please file an new issue and share some context to be able to investigate it.

@Neilski
Copy link

Neilski commented Oct 19, 2016

I do have a tsconfig.json file, the only thing that might be unusual is that is is placed in the '/tsScripts' folder off the root. This folder is where my TypeScript source files are kept, for example '/tsScripts/App1/', '/tsScripts/App2/' etc.

For your reference, here is my tsconfig.json...

{
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "module": "commonjs",
    "noEmitOnError": true,
    "noImplicitAny": false,
    "outDir": "./",
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "moduleResolution": "node",
    "types": ["node"]
  },
  "exclude": [
    "node_modules",
    "typings/index",
    "typings/index.d.ts"
  ]
}

I am not sure of why, but the project builds with the TypeScript Project Options set as described, but would not without the automatic compilation set.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 19, 2016

Can you please share a project we can try with? also i would appreciate it if you file a new issue.

@Neilski
Copy link

Neilski commented Nov 1, 2016

The project is part of a commercial contract, but I will try and replicate the problem in a new project. Thanks for your help.

@Neilski
Copy link

Neilski commented Nov 8, 2016

We have tried to replicate this problem, but without success. Interestingly, if we turn these settings off in the original project, it now compiles without error. As far as I know, nothing else has changed.

So, in summary, it appears that the problem has resolved itself, just not sure how/why.

@Argon2000
Copy link

Wow, had a big headache today when updating to TypeScript 2.0.6.. All errors returned that was fixed with the custom typescriptServices.js file (e.g. "Cannot find module 'angular2/core'", "set 'experimentalDecorators' to true", "'example' is not a valid property for window" etc. etc.).

This is what my tsconfig.json file looked like:

{
  "compilerOptions": {
    "noImplicitAny": true,
    "noEmitOnError": false,
    "sourceMap": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "module": "system",
    "moduleResolution": "Node",
    "target": "es5",
    "noImplicitUseStrict": true,
    "allowSyntheticDefaultImports": true,
    "outDir": "scripts",
    "outFile": "scripts/app.js"
  },
  "include": [
    "App",
    "Scripts"
  ],
  "exclude": [
    "node_modules",
    "Scaffolding"
  ],
  "compileOnSave": true
}

I tried everything, uninstalled all previous versions of typescript, tools for VS2015, rebooted several times etc. Nothing helped.

Then I started mixturing with the settings in my tsconfig.json file and noticed that it started working after i removed several options. And after some trial and error of adding them back one by one, the culprit was found to be the "include" option.

So my current tsconfig.json looks like this (and works with 2.0.6):

{
  "compilerOptions": {
    "noImplicitAny": true,
    "noEmitOnError": false,
    "sourceMap": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "module": "system",
    "moduleResolution": "Node",
    "target": "es5",
    "noImplicitUseStrict": true,
    "allowSyntheticDefaultImports": true,
    "outDir": "scripts",
    "outFile": "scripts/app.js"
  },
  "exclude": [
    "node_modules",
    "Scaffolding"
  ],
  "compileOnSave": true
}

Strange thing is that the previous tsconfig.json worked perfectly fine with TS 1.8.x

@mhegazy
Copy link
Contributor

mhegazy commented Nov 18, 2016

Strange thing is that the previous tsconfig.json worked perfectly fine with TS 1.8.x

include was not supported for TS 1.8, looks like you added it before, and was never used.

@Argon2000
Copy link

Argon2000 commented Nov 18, 2016

Ah, that would explain it. Thanks!

Edit: Acctually, it explains 'cannot find module ...' and '... not valid property of window' errors. But the 'experimentalDecorators' should not have been an error? (For .ts files in /App)

@amypellegrini
Copy link

Apologies if this comment does not apply, but I don't have time to follow all the details in this thread.

I restored a file for a hotfix suggested by @mhegazy on May 9, in case anyone needs it:

https://gist.github.com/amypellegrini/a48eb0c21f65dcb501766e69c2d8b765.js

Advice: use it at your own risk and do some research first,

I'm applying this hotfix as suggested by my colleagues and there are probably many details I'm missing related to this issue, I just want to make sure anyone else can have access to this file in case it needs to.

@invegat
Copy link

invegat commented Nov 28, 2016

Using rxjs "5.0.0-beta.12" I copied my local "node_modules\typescript\lib\typescriptServices.js" to "c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TypeScript" and restarted Visual Studio 2015 Update 3, the problem was fixed.

@hobojoe
Copy link

hobojoe commented Dec 1, 2016

Hi,

I've tried following all these tricks but none worked.

I created a brand new project on github with the problem:
https://github.com/hobojoe/TestApp

Does anyone have a clue of what could be the problem?

@abidmix
Copy link

abidmix commented Dec 1, 2016

@hobojoe . I added an es6-shim.d.ts to your project ...added a map import in your service and a reference to the es6-shim.d.ts and your app builds fine inside and outside visual studio. See the changes I made to your project. Confirm if this resolves your issue.

image

Outside Visual Studio

image

@hobojoe
Copy link

hobojoe commented Dec 4, 2016

Hi @abidmix
I have performed the steps suggested by you and it fixed the problem.

The strange thing is that, as mentioned by @VahidN, I was following a guide from @chsakell and I could use his project without the need to follow the steps you described.

That is odd to me, that for one project everything works without adding the custom import and mine doesn't and I have to add it to work....

Thanks anyway, your assistance was very helpful!!

@mickeyk
Copy link

mickeyk commented Dec 6, 2016

Upgrading to the latest TypeScript for Visual Studio 2015 fixed the issue for me.

Sharpiro added a commit to Sharpiro/learning that referenced this issue Sep 1, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests