question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[@sentry/node] "Cannot find name" TypeScript build errors

See original GitHub issue

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other:

Version:

4.0.0-rc.2

Description

Perhaps I’ve not correctly configured my TypeScript environment or something, but I cannot seem to successfully run tsc --build with @sentry/node, getting the following errors:

node_modules/@sentry/node/dist/handlers.d.ts:2:49 - error TS2304: Cannot find name 'Request'.

2 export declare function requestHandler(): (req: Request, res: Response, next: () => void) => void;
                                                  ~~~~~~~

node_modules/@sentry/node/dist/handlers.d.ts:2:63 - error TS2304: Cannot find name 'Response'.

2 export declare function requestHandler(): (req: Request, res: Response, next: () => void) => void;
                                                                ~~~~~~~~

node_modules/@sentry/node/dist/handlers.d.ts:13:71 - error TS2304: Cannot find name 'Request'.

13 export declare function errorHandler(): (error: MiddlewareError, req: Request, res: Response, next: (error: MiddlewareError) => void) => void;
                                                                         ~~~~~~~

node_modules/@sentry/node/dist/handlers.d.ts:13:85 - error TS2304: Cannot find name 'Response'.

13 export declare function errorHandler(): (error: MiddlewareError, req: Request, res: Response, next: (error: MiddlewareError) => void) => void;
                                                                                       ~~~~~~~~

node_modules/@sentry/node/dist/transports/base.d.ts:8:53 - error TS2304: Cannot find name 'URL'.

8     request(options: http.RequestOptions | string | URL, callback?: (res: http.IncomingMessage) => void): http.ClientRequest;
                                                      ~~~

In case it is my TypeScript configuration, the contents of tsconfig.json is:

{
	"compilerOptions": {
		"module": "commonjs",
		"target": "es2017",
		"lib": [
			"es2017"
		],
		"moduleResolution": "node",
		"rootDir": "./",
		"sourceMap": true,
		"allowJs": true,
		"noImplicitAny": true,
		"noUnusedLocals": true,
		"noImplicitThis": true,
		"strictNullChecks": true,
		"noImplicitReturns": true,
		"preserveConstEnums": true,
		"suppressImplicitAnyIndexErrors": true,
		"forceConsistentCasingInFileNames": true,
		"strict": true
	},
	"exclude": [
		"node_modules",
		"build",
		"webpack"
	],
	"types": [
		"typePatches"
	]
}

And a simple use case:

import { init } from "@sentry/node";

init({
	dsn: "..."
});

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
kamilogorekcommented, Sep 14, 2018

@Aquilosion

{ 
  "compilerOptions": {
    "lib": ["dom"]
  }
}

dom typings contain those APIs, forgot about that. Tested with your project, it works just fine. We’ll document this 😃

3reactions
kamilogorekcommented, Sep 14, 2018

@Aquilosion you have to add node typings to your project.

npm install @types/node

....

"compilerOptions": {
    "types": [
      "node"
    ],
}

Sorry for the inconvinience, it’ll be included in the docs. Cheers!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix the Cannot Find Name 'require' Error in TypeScript
To fix the “cannot find name 'require'” error in TypeScript, install the @types/node package into your project by running npm i -D @types/node...
Read more >
How to Add Sentry to Your Node.js Project with TypeScript
Sentry.io is an external monitoring and logging service which can help you identify and triage errors in your code.
Read more >
Node.js - Sentry Documentation
On this page, we get you up and running with Sentry's SDK, ... Sentry's Node SDK enables automatic reporting of errors, exceptions, and...
Read more >
TypeScript getting error TS2304: cannot find name ' require'
If you are using Webpack as your build tool you can include the Webpack types. npm install --save-dev @types/webpack-env. Update your tsconfig.json with...
Read more >
@sentry/node | Yarn - Package Manager
Important: This documentation covers modern versions of Yarn. For 1.x docs, see classic.yarnpkg.com. Yarn.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found