i'm trying to import got from 'got' in my typescript program to convert an url to a streamable file, but I tryed to import it in different ways and i obtaining always errors like : can only be default-imported using the 'esModuleInterop' flag
my question is how can I import got correctly without get errors ? Or is there another way to convert an url to a streamable file in typescript?
import { sha256 } from 'js-sha256';
import {Metadata} from './metadata';
import * as fs from 'fs'
const pinataSDK = require('@pinata/sdk');
import got from 'got';
export const ARC3_NAME_SUFFIX = "@arc3"
export const ARC3_URL_SUFFIX = "#arc3"
export const METADATA_FILE = "metadata.json"
export const JSON_TYPE = 'application/json'
export const JSONObject = "metadata.json"
export function asaURL(cid: string): string { return ipfsURL(cid)+ARC3_URL_SUFFIX }
export function ipfsURL(cid: string): string { return "ipfs://"+cid }
Add this option to your tsconfig.json file:
https://www.typescriptlang.org/tsconfig#esModuleInterop
This is needed because CJS exports and MJS exports are out of box incompatible (because CJS has no notion of a default export, but MJS does).
Enabling this interop allows TS to import CJS dependencies into its modules.
If people are still struggling with this, try using
xnrto run your source code, I created it pretty much for this purpose as interop between TS, modules and npm packages can be pretty nasty and sometimes you want something that just works! :)