Bug: TS compilation error because of missing URL type
See original GitHub issueWhen using applicationinsights
latest package ( 2.1.4
) in TS projects which target Node only (no browser), I get the following compilation error:
node_modules/applicationinsights/out/Declarations/Contracts/TelemetryTypes/NodeHttpDependencyTelemetry.d.ts:12:23 - error TS2304: Cannot find name 'URL'.
12 options: string | URL | http.RequestOptions | https.RequestOptions;
~~~
Probably you guys are missing some module import?
Very dirty workaround: I found similar error (in different NPM package): https://github.com/DefinitelyTyped/DefinitelyTyped/issues/19799 . It suggested adding dom
library as workaround. Of course, doing this for your Node project has all kinds of nasty implications, which is why I just downgraded to 1.8.10
.
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Typescript module not found error after compilation
I ran into this problem when compiling TS to ES modules with Node 15. Turns out that TS does not add the ".js"...
Read more >TypeScript errors and how to fix them
ts ' cannot be compiled under '–isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export...
Read more >Bug listing with status RESOLVED with resolution TEST ...
... Bug:72974 - "nvidia-kernel fails to compile, because of multiple problems in linux-info.eclass" status:RESOLVED resolution:TEST-REQUEST severity:normal ...
Read more >Error Messages | Cypress Documentation
This message means that Cypress encountered an error when compiling and/or bundling your test file. Cypress automatically compiles and bundles your test code...
Read more >Troubleshooting Common Errors - Gatsby
Field "image" must not have a selection since type "String" has no subfields; Problems installing sharp with gatsby-plugin-sharp - gyp ERR! build error...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I resolved this for myself by adding DOM to the tsconfig lib array:
tsconfig.json
It then compiled fine.
Long time no see! My vacation started pretty quickly after my last comment, and then I got swamped with other things. But, I found out solution that doesn’t need PR to this repo.
If you are running backend stuff, and definitely don’t want to include DOM TS library (to avoid runtime crashes which pass TS typechecks), another option is to use approach explained in @microsoft/microsoft-graph-client library:
First, install some
fetch
library for Node, e.g.cross-fetch
:Then, in your TS code, just import fetch library stuff before using
"applicationinsights"
:Now, the
tsc
will succeed without errors (make sure to havemoduleResolution
compiler config field set tonode
), and without DOM library: