Giter Club home page Giter Club logo

Comments (8)

balupton avatar balupton commented on July 22, 2024 17

So if you do import fetch from 'isomorphic-unfetch' then the types work fine, but it fails to run, due to TypeError: isomorphic_unfetch_1.default is not a function

Searching that error, returns the recommendation of doing the following for commonjs modules import fetch = require('isomorphic-unfetch') however, then typescript complains there are no types, as the type definition is done with esmodules in mind, not commonjs modules

As such, I've done the following workaround for it:

import * as fetchImport from 'isomorphic-unfetch'
const fetch = (fetchImport.default || fetchImport) as typeof fetchImport.default

from unfetch.

samayo avatar samayo commented on July 22, 2024 5

Still getting this error. Is there a fix for it?

from unfetch.

egasimus avatar egasimus commented on July 22, 2024

Same problem with [email protected] ([email protected], [email protected], [email protected]):

error TS7016: Could not find a declaration file for module 'unfetch'. '/home/user/Edge/Demo/node_modules/unfetch/dist/unfetch.js' implicitly has an 'any' type.

from unfetch.

fnatte avatar fnatte commented on July 22, 2024

@egasimus I don't think that is the same issue. Typescript definitions were added in [email protected], so that is probably why the declaration file can't be found in your case.

Some more info on my issue:

import * as fetch from 'unfetch';
console.log(fetch); // { default: f(), __esModule: true }
import fetch from 'unfetch';
// error TS1192: Module '"node_modules/unfetch/src/index"' has no default export

The last example works if I enable allowSyntheticDefaultImports, but that was not required before.

from unfetch.

O4epegb avatar O4epegb commented on July 22, 2024

Yep, just updated to v4 and have same issue. Definitions are definitely incorrect.

from unfetch.

stephenmathieson avatar stephenmathieson commented on July 22, 2024

I believe this is due to TypeScript not respecting the .mjs extension.

from unfetch.

O4epegb avatar O4epegb commented on July 22, 2024

Not true, just .d.ts is incorrect.

from unfetch.

igl avatar igl commented on July 22, 2024

if you do import fetch from 'isomorphic-unfetch' then the types work fine

What am i missing here? there are no types but just a typeof fetch which resolves to any

image

from unfetch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.