Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: Request is not defined #1134

Closed
Stono opened this issue Oct 24, 2020 · 3 comments
Closed

ReferenceError: Request is not defined #1134

Stono opened this issue Oct 24, 2020 · 3 comments

Comments

@Stono
Copy link

Stono commented Oct 24, 2020

I have an issue with Request from WebWorker.
It appears to be fine with tsc but not ts-node.

As an example:

tsconfig.json:

{
  "compilerOptions": {
    "types": ["@cloudflare/workers-types", "mocha"],
    "module": "CommonJS",
    "target": "es2020",
    "lib": ["es2017", "WebWorker"],
    "rootDir": "./",
    "outDir": "./built",
    "baseUrl": "./",
    "allowJs": true,
    "checkJs": true,
    "alwaysStrict": true,
    "noImplicitAny": false,
    "noImplicitThis": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "noEmitOnError": false,
    "sourceMap": false
  },
  "include": ["lib/**/*.ts", "test/**/*.ts"],
  "exclude": ["node_modules"]
}

and lib/example.ts:

const example = new Request({} as any)
console.log(example)

./node_modules/.bin/tsc lib/example.ts = completes fine

Intellisense in vscode = fine.

ts-node however, does not:

❯ ./node_modules/.bin/ts-node --project tsconfig.json lib/example.ts

/Users/karl.stoney/git/autotrader/at-global-worker/lib/example.ts:1
const example = new Request({} as any)
                ^
ReferenceError: Request is not defined
    at Object.<anonymous> (/Users/karl.stoney/git/autotrader/at-global-worker/lib/example.ts:1:17)
    at Module._compile (internal/modules/cjs/loader.js:1251:30)
    at Module.m._compile (/Users/karl.stoney/git/autotrader/at-global-worker/node_modules/ts-node/src/index.ts:1043:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1272:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/karl.stoney/git/autotrader/at-global-worker/node_modules/ts-node/src/index.ts:1046:12)
    at Module.load (internal/modules/cjs/loader.js:1100:32)
    at Function.Module._load (internal/modules/cjs/loader.js:962:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at main (/Users/karl.stoney/git/autotrader/at-global-worker/node_modules/ts-node/src/bin.ts:225:14)
    at Object.<anonymous> (/Users/karl.stoney/git/autotrader/at-global-worker/node_modules/ts-node/src/bin.ts:512:3)

As a result, I'm unable to use ts-node to run the project or tests.

@cspotcode
Copy link
Collaborator

cspotcode commented Oct 24, 2020 via email

@cspotcode
Copy link
Collaborator

@Stono this looks like a problem with the workers-types

Your code does new Request(). ts-node is compiling and running your code. tsc is only compiling your code. What happens when you run it? The error you are getting is not a typechecking error; it is a runtime error. Which means you get that error from node, not from ts-node.

@cspotcode
Copy link
Collaborator

I'm gonna go ahead and close this since it looks like an external issue. If you find any information that shows it's a ts-node issue, and we need to make a bugfix, let us know and we'll reopen the ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants