Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export not found on module

I have a library, in one of the files i export an interface:

export interface MyInterface {
...
}

and there is a default export, which is a react component.

On an index.ts file, I import few stuff, and re-export them:

import Something from "./Something";
import OtherStuff from "./OtherStuff";
import ExportDefault, { MyInterface } from "./QuestionFile";

export { Something, OtherStuff, ExportDefault, MyInterface };

When I compile, I get an error:

MyInterface is not exported by QuestionFile.

My goal is, whoever imports my library is able to import that type definition to use too.

Is there a better way to do that?

if I do:

export * from "./QuestionFile"

it works, otherwise it breaks my build.

An example on what is going on can be found on this repository: https://github.com/PlayMa256/typescript-babel-error

like image 825
PlayMa256 Avatar asked Sep 10 '18 12:09

PlayMa256


People also ask

What is module exports in node?

Module exports are the instructions that tell Node. js which bits of code (functions, objects, strings, etc.) to export from a given file so that other files are allowed to access the exported code.

Is module exports the same as export?

When we want to export a single class/variable/function from one module to another module, we use the module. exports way. When we want to export multiple variables/functions from one module to another, we use exports way.

Can you export with module exports?

When you export a module, you can import it into other parts of your applications and consume it. Node. js supports CommonJS Modules and ECMAScript Modules.

Can't import the named export from default exporting module only default export is available?

Can't import the named Export children from non EcmaScript module only default export is available? Solution: You Just need to Downgrade the Framer motion version to “4.1. 17” in your package. json file and then run npm install Now, Your error must be solved.


2 Answers

From https://devblogs.microsoft.com/typescript/announcing-typescript-3-8-beta/:

As a solution in TypeScript 3.8, we’ve added a new syntax for type-only imports and exports.

import type { SomeThing } from "./some-module.js";

export type { SomeThing };
like image 156
Séverin Beauvais Avatar answered Oct 21 '22 02:10

Séverin Beauvais


Re-exporting types is one of the known TypeScript constructs that don't work when using Babel to compile TypeScript because they require cross-file information. You can enable the isolatedModules TypeScript compiler option to report these constructs as errors when you compile with tsc (not Babel) or use the TypeScript language service in an IDE. export * is one workaround; another described in this issue is to use a type alias instead of a re-export. Yet another workaround is to merge a constant with the interface. (It's a hack but avoids some of the disadvantages of the other approaches.)

export interface testInterface {
    name?: string;
}
export const testInterface = undefined;
like image 45
Matt McCutchen Avatar answered Oct 21 '22 01:10

Matt McCutchen