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

Unable to build in nodejs typescript #187

Closed
odufuwa-segun opened this issue Nov 18, 2021 · 7 comments
Closed

Unable to build in nodejs typescript #187

odufuwa-segun opened this issue Nov 18, 2021 · 7 comments

Comments

@odufuwa-segun
Copy link

odufuwa-segun commented Nov 18, 2021

Steps to Reproduce

yarn build

Observed Behaviour

The build fails with typescript errors saying: Cannot find name "Response", cannot find name "RequestInit"

Image or video please.

Screenshot 2021-11-18 at 6 26 14 AM

Expected Behaviour

Expect build to be successful

Technical Notes

  • Node v14.17.6
  • Typescript v4.2.3(fails on the latest too)

Reduced test case in https://github.com/odufuwa-segun/unsplash-backend-reduced-/settings

@OliverJAsh
Copy link
Member

Please provide a reduced test case. Closing until this is provided.

@odufuwa-segun
Copy link
Author

HI @OliverJAsh, I'm not too familiar with the term reduced test case, what am I to provide?

@OliverJAsh
Copy link
Member

By reduced test case I mean something like a GitHub repository I can easily clone to reproduce the issue, in the smallest version you can provide.

@odufuwa-segun
Copy link
Author

odufuwa-segun commented Nov 18, 2021

Hi @OliverJAsh, I have added the reduced test case.

I have left the other dependencies in the package.json file so as to give a good picture of what my configuration looks like.

@odufuwa-segun
Copy link
Author

Hi @OliverJAsh, I have provided the reduced test case.

@odufuwa-segun
Copy link
Author

Hi @OliverJAsh, I've fixed the issue.

I added the code below to my initialization script and that resolved the issue. My guess is that Request, RequestInnit and Response is defined as types with the fetch which for I guess wasn't globally set when I imported node-fetch. The code just declares fetch, Request, RequestInit and Response as global.

`
import * as nodeFetch from 'node-fetch'
import { InitParams } from 'unsplash-js/dist/helpers/request';

declare global {
var fetch: typeof nodeFetch.default;
type RequestInit = nodeFetch.RequestInit;
type Response = nodeFetch.Response;
}

`

@OliverJAsh
Copy link
Member

Thank you!

This has come up a few times before:

… so I added some documentation here: b8867e9.

I raised a PR to fix your problem but it sounds like you figured it out!

odufuwa-segun/unsplash-backend-reduced-#1

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

No branches or pull requests

2 participants