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

error TS2664: Invalid module name in augmentation #9748

Closed
clavecoder opened this issue Jul 14, 2016 · 6 comments
Closed

error TS2664: Invalid module name in augmentation #9748

clavecoder opened this issue Jul 14, 2016 · 6 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@clavecoder
Copy link

Description

The What's new in TypeScript wiki page and the Announcing TypeScript 2.0 Beta blog posting
both indicate that TypeScript 2.x supports Shorthand ambient module declarations, yet when I
attempt to use declare module 'jsonschema'; for the jsonschema npm package I get

error TS2664: Invalid module name in augmentation, module 'jsonschema' cannot be found.

There is a GitHub issue (#8518) that recommends getting the latest nightly build, but I
have the latest and still get the problem. How can this be resolved?

Steps to reproduce

  1. Navigate to a parent folder

  2. Clone repo

    git clone https://github.com/clavecoder/bugreport-typescript-2-1-0-dev-20160714--invalid-module-name-in-augmentation.git

  3. cd to repo

  4. Install packages

    npm install

  5. Build project

    npm run build

Result

error TS2664: Invalid module name in augmentation, module 'jsonschema' cannot be found.

error TS2307: Cannot find module 'jsonschema'.

Output

c:\git\clavecoder\bugreport-typescript-2-1-0-dev-20160714--invalid-module-name-in-augmentation>npm run build

> bugreport-typescript-2-1-0-dev-20160714--invalid-module-name-in-augmentation@0.0.0 build c:\git\clavecoder\bugreport-typescript-2-1-0-dev-20160714--invalid-module-name-in-augmentation
> tsc

modules/test-module/src/test.ts(1,16): error TS2664: Invalid module name in augmentation, module 'jsonschema' cannot be found.
modules/test-module/src/test.ts(3,23): error TS2307: Cannot find module 'jsonschema'.

npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
npm ERR! node v6.3.0
npm ERR! npm  v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! bugreport-typescript-2-1-0-dev-20160714--invalid-module-name-in-augmentation@0.0.0 build: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the bugreport-typescript-2-1-0-dev-20160714--invalid-module-name-in-augmentation@0.0.0 build script 'tsc'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the bugreport-typescript-2-1-0-dev-20160714--invalid-module-name-in-augmentation package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     tsc
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs bugreport-typescript-2-1-0-dev-20160714--invalid-module-name-in-augmentation
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls bugreport-typescript-2-1-0-dev-20160714--invalid-module-name-in-augmentation
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     c:\git\clavecoder\bugreport-typescript-2-1-0-dev-20160714--invalid-module-name-in-augmentation\npm-debug.log

c:\git\clavecoder\bugreport-typescript-2-1-0-dev-20160714--invalid-module-name-in-augmentation>
@mhegazy
Copy link
Contributor

mhegazy commented Jul 14, 2016

the declaration declare module 'jsonschema'; should be in a global scope. i.e. a top level declaration in a non module (where a module is a file with at least one top level import or export).

A declaration of the form declare module '...' { } in a module is an augmentation, see https://github.com/Microsoft/TypeScript-Handbook/blob/fa9e2be1024014fe923d44b1b69d315e8347e444/pages/Declaration%20Merging.md#module-augmentation for more details.

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Jul 14, 2016
@mhegazy mhegazy closed this as completed Jul 14, 2016
@clavecoder
Copy link
Author

Thanks for the quick answer. Seems obvious in retrospect. Perhaps you could update the What's New documents or make sure it's included in the final documentation? It would also be nice if the error message were more helpful...

The answer was alluded to by the use of declarations.d.ts. Is that the recommended name? Where's the best place to put this file in 2.0? Are you still recommending the "typings" folder?

@muzuiget
Copy link

Ah, waste some much time to find out this issue. +1 for update What's New documents.

@clavecoder
Copy link
Author

@muzuiget, Yeah, humdinger. To +1 use the new "add your reaction" feature in GitHub.

@tugberkugurlu
Copy link

I am getting a similar error:

[ts] Invalid module name in augmentation. Module 'shiitake' resolves to an untyped module at 'd:/dev/foo/foobar.foo.Client.Web/node_modules/shiitake/dist/index.js', which cannot be augmented.

I have asked this on StackoverFlow, too: TypeScript custom declaration files for untyped npm modules

It would be nice if someone can shed some light on that.

@trusktr
Copy link
Contributor

trusktr commented Apr 12, 2017

@mhegazy Thanks for that link on augmentation, the errors really don't help much, until Googling landed me here. I am was having this problem: #4166 (comment) (solved).

@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
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

5 participants