镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

TS2307: Cannot find module  #10463

Description

@dherges
$ tsc --version
Version 2.0.0

Code

see https://github.com/proxy/gist.github.com/dherges/701e5965dd5708529410ee47e4b0c798

/// <reference path="./halfred.d.ts" />

import halfred = require('halfred');
let resource = halfred.parse({foo: "bar"});
console.log(resource);

Expected behavior:

Compilation should be ok, runtime should be ok.

Actual behavior:

Compilation throws error "TS2307: Cannot find module ". Then running the generated .js (on node) works as expected. Module is resolved (through require()) and produces expected output.

Custom typings are in place. Visual Studio Code actually recognizes the typings. However, compilation fails.

Usage error? Is this a mis-understanding or a tsc bug?

Activity

  1. DanielRosenwasser commented on Aug 21, 2016

    @DanielRosenwasser
    Member

    You want to write declare module "halfred" (notice the quotes, which implies an import path).

  2. DanielRosenwasser commented on Aug 21, 2016

    @DanielRosenwasser
    Member

    As a heads up, I opened up this bug for you: #10464

    The TL;DR is that

    • TypeScript used to have "internal" and "external" modules.
    • external modules are the same concept as what ES2015 introduced.
    • internal modules are a way of containing things locally in a world without ES modules.
    • This distinction was confusing so we renamed
      • "external modules" to "modules"
      • "internal modules" to "namespaces"

    This

    declare module "foo" {
        // ...
    }

    declares a module that you can import as "foo".

    While these

    declare namespace foo {
        // ...
    }
    
    declare module bar {
        // ...
    }

    create namespaces named foo and bar respectively. But we couldn't remove the declare module bar syntax because it was a breaking change, so now it just continues to confuse users.

  3. dherges commented on Aug 21, 2016

    @dherges
    Author

    Thanks a lot for your help! 👍

  4. DanielRosenwasser commented on Aug 21, 2016

    @DanielRosenwasser
    Member

    You're welcome!

  5. 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