Skip to content

error TS2664: Invalid module name in augmentation #9748

Description

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>

Activity

  1. mhegazy commented on Jul 14, 2016

    @mhegazy
    Contributor

    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.

  2. clavecoder commented on Jul 15, 2016

    @clavecoder
    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?

  3. muzuiget commented on Jul 28, 2016

    @muzuiget

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

  4. clavecoder commented on Jul 28, 2016

    @clavecoder
    Author

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

  5. tugberkugurlu commented on Mar 9, 2017

    @tugberkugurlu

    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.

  6. trusktr commented on Apr 12, 2017

    @trusktr
    Contributor

    Mohamed Hegazy (@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).

  7. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions