You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot find type definition file for ambient declaration module #34749
// A *self-contained* demonstration of the problem follows...[typings/somemodule/index.d.ts]declare module "somemodule"{exportnamespacecommon{exportinterfaceFoo{bar: string;fuzz: Number;}}}[src/index.ts]/// <reference path="../typings/somemodule/index.d.ts" />
Typescript 3.5.3 works as expected, anything at or above 3.6 has the same issue..
When running tsc -d, for a manually created declaration file, the triple slash reference path file should be preserved in the output declaration file. This particular declaration file acts as a shim for an existing library whose type definitions are incomplete and is to be included as-is and without transpiler manipulation in the output declaration file. This provides accurate intellisense for package consumers and ensures build errors do not occur.
Expected behavior:
Maintain the same triple-slash reference path in the .d.ts file as was in the .ts file.
This causes consuming applications of the package to receive the following build error: Cannot find type definition file for 'typings/somemodule'.
I have been unsuccessful in manipulating the consuming application to build correctly or provide correct intellisense with the updated directive. The original directive must be preserved.
Playground Link:
Related Issues: I believe this is where the issue was introduced: #32878
IIRC reference types is only used when a package is within a node_modules folder - is your source tree within a node_modules folder or using some other method to make that path seem valid to TS? What are your compilerOptions? Are you using baseUrl?
Our source tree is not with a node_modules folder, and indeed we are using baseUrl. But in the particular project I'm seeing this failing (it could be many more, but compilation just stops there after this failure), the value for baseUrl is ../ and also mergeReferenceces is true, as this small project is built within some other bigger project:
Scrap a little bit of that. The failure is happening in the project I mentioned above, but the incorrect definition file is being created in a project it depends on. The project where the incorrect dependency is being generated has this configuration:
It's the baseUrl flag. The emitter is configured to prefer non-relative reference types style refs where possible, and the baseUrl parameter alters resolution to allow non-relative references starting at the location specified by the baseUrl.
In short: The baseUrl flag (combined with commonjs module resolution rules regarding extensions and indexes) is telling the compiler that it's OK to reference that file via the path typings/somemodule, and it's now using that knowledge to generate a "nicer" (and usually more portable) reference.
Julian Dominguez (@jdom) would you be able to move your typings folder out of your baseUrl directory? Since you're not shipping them into the combined root that a baseUrl resolution relies on, it doesn;t really make sense for them to be under the input baseUrl directory.
I'm a little hesitant to do this change, as we have tons of legacy external tooling that works with the current structure, and we also generate different definitions and bundles for different SDKs. If there is a way to get the previous behavior (ie: since my source code is explicitly using a relative reference, keep it relative in the emitter), then I'd certainly prefer that. Do you think it can be achieved with the current release?
We just ran into something similar to this; I'm unclear on whether it's exactly the same issue or just related on the surface. We have a handful of internal packages that declare types for public ones that don't have their own declarations (essentially like a miniature internal DT).
Consumers of these typings include an import somewhere in their source and then are able to otherwise interact with the target packages normally:
While it definitely seems like a good thing to have that reference included instead of relying on the downstream consumer to have imported the declarations themselves, the path emitted doesn't seem to resolve correctly. I think the leading node_modules/ is causing issues?
We do have a baseUrl set (and can't easily migrate off it because of a fair amount of paths usage), but I'm a bit surprised that node_modules is appearing in the path at all.
Edit: I just realized this behavior is different based on the declarationDir we use. If it's outside the project directory (and thus outside the baseUrl), the path includes node_modules, but if it's within the project directory, it doesn't. Is it expected that the place declarations are being emitted to would impact their contents?
I'm running into this problem too, in a umd common project that's included on the server (which is a commonjs node project) and the client (which is an amd web-browser project). This causes compilation of both the server and the client to fail.
Additionally the ./ and .d.ts are removed from the path, so /// <reference path="./GlobalDefinitions.d.ts" /> becomes /// <reference types="globaldefinitions" /> which fails.
Activity
jdom commentedon Oct 29, 2019
I'm repro'ing this too. I was updating from 3.3 to 3.6 and hit this issue. Now I'm falling back to 3.5 which doesn't repro this issue
weswigham commentedon Oct 30, 2019
IIRC
reference typesis only used when a package is within anode_modulesfolder - is your source tree within anode_modulesfolder or using some other method to make that path seem valid to TS? What are yourcompilerOptions? Are you usingbaseUrl?jdom commentedon Oct 30, 2019
Our source tree is not with a
node_modulesfolder, and indeed we are usingbaseUrl. But in the particular project I'm seeing this failing (it could be many more, but compilation just stops there after this failure), the value forbaseUrlis../and alsomergeReferencecesistrue, as this small project is built within some other bigger project:And the base config referenced in the previous config is this:
jdom commentedon Oct 30, 2019
Scrap a little bit of that. The failure is happening in the project I mentioned above, but the incorrect definition file is being created in a project it depends on. The project where the incorrect dependency is being generated has this configuration:
The base config file is the same as what i pasted in my previous comment.
weswigham commentedon Oct 30, 2019
It's the
baseUrlflag. The emitter is configured to prefer non-relativereference typesstyle refs where possible, and thebaseUrlparameter alters resolution to allow non-relative references starting at the location specified by thebaseUrl.weswigham commentedon Oct 30, 2019
In short: The
baseUrlflag (combined with commonjs module resolution rules regarding extensions andindexes) is telling the compiler that it's OK to reference that file via the pathtypings/somemodule, and it's now using that knowledge to generate a "nicer" (and usually more portable) reference.weswigham commentedon Oct 30, 2019
Julian Dominguez (@jdom) would you be able to move your
typingsfolder out of yourbaseUrldirectory? Since you're not shipping them into the combined root that abaseUrlresolution relies on, it doesn;t really make sense for them to be under the inputbaseUrldirectory.tschettler commentedon Oct 31, 2019
Yes, I use baseUrl and if I don't, the triple slash reference is left alone. Here's my tsconfig.json.
Does this mean baseUrl cannot be used when the project uses triple slash reference paths?
jdom commentedon Oct 31, 2019
I'm a little hesitant to do this change, as we have tons of legacy external tooling that works with the current structure, and we also generate different definitions and bundles for different SDKs. If there is a way to get the previous behavior (ie: since my source code is explicitly using a relative reference, keep it relative in the emitter), then I'd certainly prefer that. Do you think it can be achieved with the current release?
dfreeman commentedon Nov 5, 2019
We just ran into something similar to this; I'm unclear on whether it's exactly the same issue or just related on the surface. We have a handful of internal packages that declare types for public ones that don't have their own declarations (essentially like a miniature internal DT).
Consumers of these typings include an
importsomewhere in their source and then are able to otherwise interact with the target packages normally:Up to TS 3.5, when emitting declarations in this scenario, we'd get output like this:
As of 3.6, we instead see:
While it definitely seems like a good thing to have that reference included instead of relying on the downstream consumer to have imported the declarations themselves, the path emitted doesn't seem to resolve correctly. I think the leading
node_modules/is causing issues?We do have a
baseUrlset (and can't easily migrate off it because of a fair amount ofpathsusage), but I'm a bit surprised thatnode_modulesis appearing in the path at all.Edit: I just realized this behavior is different based on the
declarationDirwe use. If it's outside the project directory (and thus outside thebaseUrl), the path includesnode_modules, but if it's within the project directory, it doesn't. Is it expected that the place declarations are being emitted to would impact their contents?Griffork commentedon Dec 7, 2020
I'm running into this problem too, in a umd common project that's included on the server (which is a commonjs node project) and the client (which is an amd web-browser project). This causes compilation of both the server and the client to fail.
Additionally the ./ and .d.ts are removed from the path, so
/// <reference path="./GlobalDefinitions.d.ts" />becomes/// <reference types="globaldefinitions" />which fails.