I reduced the issue to this example:
test.model.ts
export class A { a: number; } export interface B { b: number; }
test.component.ts
import { Component, Input } from '@angular/core'; import { A, B } from './test.model'; @Component({ selector: 'test', template: '<h1>test</h1>' }) export class TestComponent { //This works fine @Input() foo: A; //Does NOT work - export 'B' was not found in './test.model' @Input() bar: B; }
When I want to use an interface I get following warning:
WARNING in ./src/app/.../test.component.ts 21:76 export 'B' was not found in './test.model'
However, using a class is OK. Any hint?
UPDATE: It seems to be somehow related to this issue: https://github.com/webpack/webpack/issues/2977
TypeScript supports export = to model the traditional CommonJS and AMD workflow. The export = syntax specifies a single object that is exported from the module. This can be a class, interface, namespace, function, or enum.
The "export default was not found" error occurs when we try to import as default from a module that doesn't have a default export. To solve the error, make sure the module has a named export and wrap the import in curly braces, e.g. import {myFunction} from './myModule' .
The error "Module has no exported member" occurs when we try to import a member that doesn't exist in the specified module. To solve the error, make sure the module exports the specific member and you haven't mistyped the name or mistaken named for default import. Copied!
The exported interface can be imported by using a named import as import {Person} from './another-file' . You can have as many named exports as necessary in a single file. Here is an example of exporting an interface from a file called another-file. ts .
The root cause is in Typescript and transpilation. Once TypeScript code is transpiled, interfaces/types are gone. They don't exist anymore in the emitted files.
While the types are erased, the imports/exports aren't necessarily. The reason is that there are ambiguities and that the compiler doesn't always know for sure whether something that is exported is a type or a value.
When using TypeScript 3.8
and up, all you need to do in your test.component.ts
is simply this:
import { A } from './test.model'; import type { B } from './test.model';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With