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
typescript npm module node-modules
add a comment |
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
typescript npm module node-modules
add a comment |
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
typescript npm module node-modules
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
typescript npm module node-modules
edited Nov 9 at 17:11
asked Nov 9 at 16:13
Veetaha
79110
79110
add a comment |
add a comment |
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:
- (Deleted)
- Have the outer project import
vee-type-safe/build/express
, which will resolve tovee-type-safe/build/express/index.d.ts
. - Remove the
outDir
option fromvee-type-safe
so that the.d.ts
files are generated alongside the.ts
files. - Redirect
vee-type-safe/express
(and each other submodule path you want other projects to be able to import) individually to the proper files underbuild
by manually creating either a pair of.js
and.d.ts
files that import the real paths or apackage.json
file withmain
andtypes
fields that refer to the real paths. (Update: It looks likemain
is enough because TypeScript will try changing the extension of themain
path.)
See this issue for additional discussion.
Thank you, I've already resolved this issue using the 4-th option having an individualpackage.json
for myexpress
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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:
- (Deleted)
- Have the outer project import
vee-type-safe/build/express
, which will resolve tovee-type-safe/build/express/index.d.ts
. - Remove the
outDir
option fromvee-type-safe
so that the.d.ts
files are generated alongside the.ts
files. - Redirect
vee-type-safe/express
(and each other submodule path you want other projects to be able to import) individually to the proper files underbuild
by manually creating either a pair of.js
and.d.ts
files that import the real paths or apackage.json
file withmain
andtypes
fields that refer to the real paths. (Update: It looks likemain
is enough because TypeScript will try changing the extension of themain
path.)
See this issue for additional discussion.
Thank you, I've already resolved this issue using the 4-th option having an individualpackage.json
for myexpress
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
add a comment |
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:
- (Deleted)
- Have the outer project import
vee-type-safe/build/express
, which will resolve tovee-type-safe/build/express/index.d.ts
. - Remove the
outDir
option fromvee-type-safe
so that the.d.ts
files are generated alongside the.ts
files. - Redirect
vee-type-safe/express
(and each other submodule path you want other projects to be able to import) individually to the proper files underbuild
by manually creating either a pair of.js
and.d.ts
files that import the real paths or apackage.json
file withmain
andtypes
fields that refer to the real paths. (Update: It looks likemain
is enough because TypeScript will try changing the extension of themain
path.)
See this issue for additional discussion.
Thank you, I've already resolved this issue using the 4-th option having an individualpackage.json
for myexpress
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
add a comment |
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:
- (Deleted)
- Have the outer project import
vee-type-safe/build/express
, which will resolve tovee-type-safe/build/express/index.d.ts
. - Remove the
outDir
option fromvee-type-safe
so that the.d.ts
files are generated alongside the.ts
files. - Redirect
vee-type-safe/express
(and each other submodule path you want other projects to be able to import) individually to the proper files underbuild
by manually creating either a pair of.js
and.d.ts
files that import the real paths or apackage.json
file withmain
andtypes
fields that refer to the real paths. (Update: It looks likemain
is enough because TypeScript will try changing the extension of themain
path.)
See this issue for additional discussion.
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:
- (Deleted)
- Have the outer project import
vee-type-safe/build/express
, which will resolve tovee-type-safe/build/express/index.d.ts
. - Remove the
outDir
option fromvee-type-safe
so that the.d.ts
files are generated alongside the.ts
files. - Redirect
vee-type-safe/express
(and each other submodule path you want other projects to be able to import) individually to the proper files underbuild
by manually creating either a pair of.js
and.d.ts
files that import the real paths or apackage.json
file withmain
andtypes
fields that refer to the real paths. (Update: It looks likemain
is enough because TypeScript will try changing the extension of themain
path.)
See this issue for additional discussion.
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 individualpackage.json
for myexpress
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
add a comment |
Thank you, I've already resolved this issue using the 4-th option having an individualpackage.json
for myexpress
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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