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.

Suggestions regarding typescript + export = FormData

See original GitHub issue

One of our users ran into a problem due to the typing of form-data 😦 Specifically the error:

tsc --outDir lib

node_modules/gitlab/dist/infrastructure/index.d.ts:2:8 - error TS1259: Module '"D:/my-project/node_modules/@types/form-data/index"' can only be default-imported using the 'esModuleInterop' flag

2 import FormData from 'form-data';
         ~~~~~~~~

  node_modules/@types/form-data/index.d.ts:15:1
    15 export = FormData;
       ~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

In the node-gitlab library, the lines that reference form-data are:

import FormData from 'form-data';
...
export interface DefaultRequestOptions extends Sudo {
  body?: object | FormData;
  query?: object;
}

And I have esModuleInterlop set in my tsconfig.

I’m not really sure how to go about solving this problem, any suggestions ? πŸ˜•

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:15

github_iconTop GitHub Comments

3reactions
jdalrymplecommented, Sep 4, 2019

https://github.com/jdalrymple/node-gitlab/issues/417#issuecomment-526574251 Our solution was changing the import for this one ts file:

https://github.com/jdalrymple/node-gitlab/commit/91cfbf27379be535ed90872ce0ea37b29e206d5c

The problem with making that change everwhere is the creation of another error which correctly states that FormData isnt callable since import * as FormData from 'form-data' should be an object

1reaction
netaisllccommented, Aug 28, 2019

Cannot repro. We are consuming form-data via request:

β”œβ”€β”¬ request@2.88.0
β”‚ β”œβ”€β”€ aws-sign2@0.7.0
β”‚ β”œβ”€β”€ aws4@1.8.0
β”‚ β”œβ”€β”€ caseless@0.12.0
β”‚ β”œβ”€β”¬ combined-stream@1.0.8
β”‚ β”‚ └── delayed-stream@1.0.0
β”‚ β”œβ”€β”€ extend@3.0.2
β”‚ β”œβ”€β”€ forever-agent@0.6.1
β”‚ β”œβ”€β”¬ form-data@2.3.3
β”‚ β”‚ └── asynckit@0.4.0
β”‚ β”œβ”€β”¬ har-validator@5.1.3
β”‚ β”‚ β”œβ”€β”¬ ajv@6.10.2
β”‚ β”‚ β”‚ β”œβ”€β”€ fast-deep-equal@2.0.1
β”‚ β”‚ β”‚ β”œβ”€β”€ json-schema-traverse@0.4.1
β”‚ β”‚ β”‚ └─┬ uri-js@4.2.2
β”‚ β”‚ β”‚   └── punycode@2.1.1
β”‚ β”‚ └── har-schema@2.0.0
β”‚ β”œβ”€β”¬ http-signature@1.2.0
β”‚ β”‚ β”œβ”€β”€ assert-plus@1.0.0
β”‚ β”‚ β”œβ”€β”¬ jsprim@1.4.1
β”‚ β”‚ β”‚ β”œβ”€β”€ extsprintf@1.3.0
β”‚ β”‚ β”‚ β”œβ”€β”€ json-schema@0.2.3
β”‚ β”‚ β”‚ └── verror@1.10.0
β”‚ β”‚ └─┬ sshpk@1.16.1
β”‚ β”‚   β”œβ”€β”€ asn1@0.2.4
β”‚ β”‚   β”œβ”€β”€ bcrypt-pbkdf@1.0.2
β”‚ β”‚   β”œβ”€β”€ dashdash@1.14.1
β”‚ β”‚   β”œβ”€β”€ ecc-jsbn@0.1.2
β”‚ β”‚   β”œβ”€β”€ getpass@0.1.7
β”‚ β”‚   β”œβ”€β”€ jsbn@0.1.1
β”‚ β”‚   └── tweetnacl@0.14.5

But making a small repro project, installing request and using TypeScript 3.5.3 does not recreate the problem. Sorry I can’t help more.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Suggestions regarding typescript + export = FormData
A module to create readable `"multipart/form-data"` streams. Can be used to submit forms and file uploads to other web applications. See MoreΒ ...
Read more >
Require fields in FormData using TypeScript - Stack Overflow
So I want to use TypeScript to check if my formData has all required fields. so I can do: export const mapRequest =...
Read more >
Uploading Files with FormData and Post Requests Using ...
In this quick tutorial, we'll learn to upload files in Angular 14 using FormData and POST requests via Angular 14 HttpClient Go to...
Read more >
TS Support | React Hook Form - Simple React forms validation
Typescript Support. List of exported Typescript Types. ... Important: Typescript ^4.3 above is the recommended version to work with react hook form.
Read more >
typescript-cheatsheet - GitHub Pages
Conversely, to consume a variable, function, class, interface, etc. exported from a different module, it has to be imported using one of the...
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