TypeScript. Ambient declaration was not found when importing “module/subdirectory” npm package









up vote
1
down vote

favorite












I am developing a library called 'vee-type-safe' for runtime type checking. Everything worked beautifully untill I added a subdirectory /express and a file /express/index.ts where I export some ExpressJS middleware type checking factories.
So I have the following structure:



vee-type-safe
|- build
|- package.json
|- declarations
| |- is-iso-date.d.ts
|
|- tsconfig.json
|- index.ts // lightweight core library
|- express
|-index.ts // express middleware factories


In express/index.ts file I import my library core '../index.ts' module.
In my core module I have the following import:



import isISODate = require('is-iso-date');


'is-iso-date' package has no typings, so I created declarations directory with is-iso-date.d.ts which is as simple as this:



declare module 'is-iso-date' 
function isISODate(suspect: string): boolean;
export = isISODate;



I added "typeRoots": [ ..., "declarations"] to tsconfig.json



I added "types": "build/index.d.ts" to package.json



When I run tsc in my package everything compiles with no errors.
But when I install my 'vee-type-safe' library as a dependency to some project via npm and try to compile it, I get the following error:



Could not find a declaration file for module 'is-iso-date'. 
'/home/tegeran/projects/is-iso-date-issue/node_modules/is-iso-date/index.js'
implicitly has an 'any'type.
Try `npm install @types/is-iso-date` if it exists or add a new declaration (.d.ts)
file containing `declare module 'is-iso-date';`

1 import isISODate = require('is-iso-date');


This happens only when I import 'vee-type-safe/express' submodule. When I import my core 'vee-type-safe' module, no errors are generated. What am I missing here?
I created a github repo with a bare minimum project to demonstrate this error










share|improve this question



























    up vote
    1
    down vote

    favorite












    I am developing a library called 'vee-type-safe' for runtime type checking. Everything worked beautifully untill I added a subdirectory /express and a file /express/index.ts where I export some ExpressJS middleware type checking factories.
    So I have the following structure:



    vee-type-safe
    |- build
    |- package.json
    |- declarations
    | |- is-iso-date.d.ts
    |
    |- tsconfig.json
    |- index.ts // lightweight core library
    |- express
    |-index.ts // express middleware factories


    In express/index.ts file I import my library core '../index.ts' module.
    In my core module I have the following import:



    import isISODate = require('is-iso-date');


    'is-iso-date' package has no typings, so I created declarations directory with is-iso-date.d.ts which is as simple as this:



    declare module 'is-iso-date' 
    function isISODate(suspect: string): boolean;
    export = isISODate;



    I added "typeRoots": [ ..., "declarations"] to tsconfig.json



    I added "types": "build/index.d.ts" to package.json



    When I run tsc in my package everything compiles with no errors.
    But when I install my 'vee-type-safe' library as a dependency to some project via npm and try to compile it, I get the following error:



    Could not find a declaration file for module 'is-iso-date'. 
    '/home/tegeran/projects/is-iso-date-issue/node_modules/is-iso-date/index.js'
    implicitly has an 'any'type.
    Try `npm install @types/is-iso-date` if it exists or add a new declaration (.d.ts)
    file containing `declare module 'is-iso-date';`

    1 import isISODate = require('is-iso-date');


    This happens only when I import 'vee-type-safe/express' submodule. When I import my core 'vee-type-safe' module, no errors are generated. What am I missing here?
    I created a github repo with a bare minimum project to demonstrate this error










    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am developing a library called 'vee-type-safe' for runtime type checking. Everything worked beautifully untill I added a subdirectory /express and a file /express/index.ts where I export some ExpressJS middleware type checking factories.
      So I have the following structure:



      vee-type-safe
      |- build
      |- package.json
      |- declarations
      | |- is-iso-date.d.ts
      |
      |- tsconfig.json
      |- index.ts // lightweight core library
      |- express
      |-index.ts // express middleware factories


      In express/index.ts file I import my library core '../index.ts' module.
      In my core module I have the following import:



      import isISODate = require('is-iso-date');


      'is-iso-date' package has no typings, so I created declarations directory with is-iso-date.d.ts which is as simple as this:



      declare module 'is-iso-date' 
      function isISODate(suspect: string): boolean;
      export = isISODate;



      I added "typeRoots": [ ..., "declarations"] to tsconfig.json



      I added "types": "build/index.d.ts" to package.json



      When I run tsc in my package everything compiles with no errors.
      But when I install my 'vee-type-safe' library as a dependency to some project via npm and try to compile it, I get the following error:



      Could not find a declaration file for module 'is-iso-date'. 
      '/home/tegeran/projects/is-iso-date-issue/node_modules/is-iso-date/index.js'
      implicitly has an 'any'type.
      Try `npm install @types/is-iso-date` if it exists or add a new declaration (.d.ts)
      file containing `declare module 'is-iso-date';`

      1 import isISODate = require('is-iso-date');


      This happens only when I import 'vee-type-safe/express' submodule. When I import my core 'vee-type-safe' module, no errors are generated. What am I missing here?
      I created a github repo with a bare minimum project to demonstrate this error










      share|improve this question















      I am developing a library called 'vee-type-safe' for runtime type checking. Everything worked beautifully untill I added a subdirectory /express and a file /express/index.ts where I export some ExpressJS middleware type checking factories.
      So I have the following structure:



      vee-type-safe
      |- build
      |- package.json
      |- declarations
      | |- is-iso-date.d.ts
      |
      |- tsconfig.json
      |- index.ts // lightweight core library
      |- express
      |-index.ts // express middleware factories


      In express/index.ts file I import my library core '../index.ts' module.
      In my core module I have the following import:



      import isISODate = require('is-iso-date');


      'is-iso-date' package has no typings, so I created declarations directory with is-iso-date.d.ts which is as simple as this:



      declare module 'is-iso-date' 
      function isISODate(suspect: string): boolean;
      export = isISODate;



      I added "typeRoots": [ ..., "declarations"] to tsconfig.json



      I added "types": "build/index.d.ts" to package.json



      When I run tsc in my package everything compiles with no errors.
      But when I install my 'vee-type-safe' library as a dependency to some project via npm and try to compile it, I get the following error:



      Could not find a declaration file for module 'is-iso-date'. 
      '/home/tegeran/projects/is-iso-date-issue/node_modules/is-iso-date/index.js'
      implicitly has an 'any'type.
      Try `npm install @types/is-iso-date` if it exists or add a new declaration (.d.ts)
      file containing `declare module 'is-iso-date';`

      1 import isISODate = require('is-iso-date');


      This happens only when I import 'vee-type-safe/express' submodule. When I import my core 'vee-type-safe' module, no errors are generated. What am I missing here?
      I created a github repo with a bare minimum project to demonstrate this error







      typescript npm module node-modules






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 17:11

























      asked Nov 9 at 16:13









      Veetaha

      79110




      79110






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          When you run tsc on the outer project, the tsconfig.json file of vee-type-safe is not in effect, so nothing forces tsc to load vee-type-safe/declarations/is-iso-date.d.ts. For an import of vee-type-safe, this is OK because the types field of vee-type-safe/package.json redirects to vee-type-safe/build/index.d.ts, which does not refer to is-iso-date since vee-type-safe/index.ts uses is-iso-date only in the implementation and does not expose any types from it. However, an import of vee-type-safe/express bypasses vee-type-safe/package.json and loads vee-type-safe/express/index.ts directly, and that file imports vee-type-safe/index.ts, which imports is-iso-date, and you get the error. More importantly, the import of vee-type-safe/express won't work at runtime because it doesn't resolve to a .js file.



          You have a few options to fix this, none of them great:



          1. (Deleted)

          2. Have the outer project import vee-type-safe/build/express, which will resolve to vee-type-safe/build/express/index.d.ts.

          3. Remove the outDir option from vee-type-safe so that the .d.ts files are generated alongside the .ts files.

          4. Redirect vee-type-safe/express (and each other submodule path you want other projects to be able to import) individually to the proper files under build by manually creating either a pair of .js and .d.ts files that import the real paths or a package.json file with main and types fields that refer to the real paths. (Update: It looks like main is enough because TypeScript will try changing the extension of the main path.)

          See this issue for additional discussion.






          share|improve this answer






















          • Thank you, I've already resolved this issue using the 4-th option having an individual package.json for my express submodule, though I only specified "main": "../build/express/index.js property without "types" and everything works fine, hmm... I don't even know why(. However, thank you for your splendid explanation )
            – Veetaha
            Nov 11 at 1:06











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229412%2ftypescript-ambient-declaration-was-not-found-when-importing-module-subdirector%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          When you run tsc on the outer project, the tsconfig.json file of vee-type-safe is not in effect, so nothing forces tsc to load vee-type-safe/declarations/is-iso-date.d.ts. For an import of vee-type-safe, this is OK because the types field of vee-type-safe/package.json redirects to vee-type-safe/build/index.d.ts, which does not refer to is-iso-date since vee-type-safe/index.ts uses is-iso-date only in the implementation and does not expose any types from it. However, an import of vee-type-safe/express bypasses vee-type-safe/package.json and loads vee-type-safe/express/index.ts directly, and that file imports vee-type-safe/index.ts, which imports is-iso-date, and you get the error. More importantly, the import of vee-type-safe/express won't work at runtime because it doesn't resolve to a .js file.



          You have a few options to fix this, none of them great:



          1. (Deleted)

          2. Have the outer project import vee-type-safe/build/express, which will resolve to vee-type-safe/build/express/index.d.ts.

          3. Remove the outDir option from vee-type-safe so that the .d.ts files are generated alongside the .ts files.

          4. Redirect vee-type-safe/express (and each other submodule path you want other projects to be able to import) individually to the proper files under build by manually creating either a pair of .js and .d.ts files that import the real paths or a package.json file with main and types fields that refer to the real paths. (Update: It looks like main is enough because TypeScript will try changing the extension of the main path.)

          See this issue for additional discussion.






          share|improve this answer






















          • Thank you, I've already resolved this issue using the 4-th option having an individual package.json for my express submodule, though I only specified "main": "../build/express/index.js property without "types" and everything works fine, hmm... I don't even know why(. However, thank you for your splendid explanation )
            – Veetaha
            Nov 11 at 1:06















          up vote
          1
          down vote



          accepted










          When you run tsc on the outer project, the tsconfig.json file of vee-type-safe is not in effect, so nothing forces tsc to load vee-type-safe/declarations/is-iso-date.d.ts. For an import of vee-type-safe, this is OK because the types field of vee-type-safe/package.json redirects to vee-type-safe/build/index.d.ts, which does not refer to is-iso-date since vee-type-safe/index.ts uses is-iso-date only in the implementation and does not expose any types from it. However, an import of vee-type-safe/express bypasses vee-type-safe/package.json and loads vee-type-safe/express/index.ts directly, and that file imports vee-type-safe/index.ts, which imports is-iso-date, and you get the error. More importantly, the import of vee-type-safe/express won't work at runtime because it doesn't resolve to a .js file.



          You have a few options to fix this, none of them great:



          1. (Deleted)

          2. Have the outer project import vee-type-safe/build/express, which will resolve to vee-type-safe/build/express/index.d.ts.

          3. Remove the outDir option from vee-type-safe so that the .d.ts files are generated alongside the .ts files.

          4. Redirect vee-type-safe/express (and each other submodule path you want other projects to be able to import) individually to the proper files under build by manually creating either a pair of .js and .d.ts files that import the real paths or a package.json file with main and types fields that refer to the real paths. (Update: It looks like main is enough because TypeScript will try changing the extension of the main path.)

          See this issue for additional discussion.






          share|improve this answer






















          • Thank you, I've already resolved this issue using the 4-th option having an individual package.json for my express submodule, though I only specified "main": "../build/express/index.js property without "types" and everything works fine, hmm... I don't even know why(. However, thank you for your splendid explanation )
            – Veetaha
            Nov 11 at 1:06













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          When you run tsc on the outer project, the tsconfig.json file of vee-type-safe is not in effect, so nothing forces tsc to load vee-type-safe/declarations/is-iso-date.d.ts. For an import of vee-type-safe, this is OK because the types field of vee-type-safe/package.json redirects to vee-type-safe/build/index.d.ts, which does not refer to is-iso-date since vee-type-safe/index.ts uses is-iso-date only in the implementation and does not expose any types from it. However, an import of vee-type-safe/express bypasses vee-type-safe/package.json and loads vee-type-safe/express/index.ts directly, and that file imports vee-type-safe/index.ts, which imports is-iso-date, and you get the error. More importantly, the import of vee-type-safe/express won't work at runtime because it doesn't resolve to a .js file.



          You have a few options to fix this, none of them great:



          1. (Deleted)

          2. Have the outer project import vee-type-safe/build/express, which will resolve to vee-type-safe/build/express/index.d.ts.

          3. Remove the outDir option from vee-type-safe so that the .d.ts files are generated alongside the .ts files.

          4. Redirect vee-type-safe/express (and each other submodule path you want other projects to be able to import) individually to the proper files under build by manually creating either a pair of .js and .d.ts files that import the real paths or a package.json file with main and types fields that refer to the real paths. (Update: It looks like main is enough because TypeScript will try changing the extension of the main path.)

          See this issue for additional discussion.






          share|improve this answer














          When you run tsc on the outer project, the tsconfig.json file of vee-type-safe is not in effect, so nothing forces tsc to load vee-type-safe/declarations/is-iso-date.d.ts. For an import of vee-type-safe, this is OK because the types field of vee-type-safe/package.json redirects to vee-type-safe/build/index.d.ts, which does not refer to is-iso-date since vee-type-safe/index.ts uses is-iso-date only in the implementation and does not expose any types from it. However, an import of vee-type-safe/express bypasses vee-type-safe/package.json and loads vee-type-safe/express/index.ts directly, and that file imports vee-type-safe/index.ts, which imports is-iso-date, and you get the error. More importantly, the import of vee-type-safe/express won't work at runtime because it doesn't resolve to a .js file.



          You have a few options to fix this, none of them great:



          1. (Deleted)

          2. Have the outer project import vee-type-safe/build/express, which will resolve to vee-type-safe/build/express/index.d.ts.

          3. Remove the outDir option from vee-type-safe so that the .d.ts files are generated alongside the .ts files.

          4. Redirect vee-type-safe/express (and each other submodule path you want other projects to be able to import) individually to the proper files under build by manually creating either a pair of .js and .d.ts files that import the real paths or a package.json file with main and types fields that refer to the real paths. (Update: It looks like main is enough because TypeScript will try changing the extension of the main path.)

          See this issue for additional discussion.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 11 at 3:08

























          answered Nov 11 at 0:06









          Matt McCutchen

          13.2k719




          13.2k719











          • Thank you, I've already resolved this issue using the 4-th option having an individual package.json for my express submodule, though I only specified "main": "../build/express/index.js property without "types" and everything works fine, hmm... I don't even know why(. However, thank you for your splendid explanation )
            – Veetaha
            Nov 11 at 1:06

















          • Thank you, I've already resolved this issue using the 4-th option having an individual package.json for my express submodule, though I only specified "main": "../build/express/index.js property without "types" and everything works fine, hmm... I don't even know why(. However, thank you for your splendid explanation )
            – Veetaha
            Nov 11 at 1:06
















          Thank you, I've already resolved this issue using the 4-th option having an individual package.json for my express submodule, though I only specified "main": "../build/express/index.js property without "types" and everything works fine, hmm... I don't even know why(. However, thank you for your splendid explanation )
          – Veetaha
          Nov 11 at 1:06





          Thank you, I've already resolved this issue using the 4-th option having an individual package.json for my express submodule, though I only specified "main": "../build/express/index.js property without "types" and everything works fine, hmm... I don't even know why(. However, thank you for your splendid explanation )
          – Veetaha
          Nov 11 at 1:06


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229412%2ftypescript-ambient-declaration-was-not-found-when-importing-module-subdirector%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

          Crossroads (UK TV series)

          ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế