I’m submitting a bug report
Webpack version:
2.1.0-beta.22
Please tell us about your environment:
Windows 10
Current behavior:
https://github.com/Tragetaschen/webpack-interface-import-warning
When running webpack beta.22
, two warnings appear:
WARNING in ./main.ts
16:51 export 'Bar' was not found in './src'
WARNING in ./main.ts
16:74 export 'Bar' was not found in './src'
Expected/desired behavior:
beta.21
doesn’t show these.
There are some ways to make the warning go away:
- In
src/index.ts
, replaceexport * from './bar'
withexport {Bar} from './bar'
- In
src/index.ts
, comment outexport * from './foo'
(sic!)
I can see that the awesome-typescript-loader introduces code that references the interface name (although running bare TypeScript erases it successfully), but those two workarounds above make me think something is odd with webpack.
typescript transpiles
export interface Bar {}
to nothing. This means there is nothing exported frombar
. webpack correctly shows a warning that the export was not found.The problem is that the exported interface is really used in the generated type:
Note that the code still works, because typescript checks for undefined here, but a ES6 Modules implementation may throw here (webpack displays a warning).
Please report this issue to typescript itself.
It should either generate an export from interface.
Or it should not use the imported variable if it’s an interface (which is not generated).
I experience this same issue using
awesome-typescript-loader
.ts-loader
doesn’t seem to have this issue.Same issue with string literal types.
Consider
moduleA.ts
:Then import it in
moduleB.ts
:WARNING: export ‘AvatarType’ was not found in ‘./moduleA’
We also get similar warnings here, in one case a string enum type id not found eg.
export type Provider = 'asdf' | 'bsdf' | ...;
In the other an interface definition is not found.
TypeScript should be eliding any imports that aren’t used as values. I’m not sure what could be going on here.
Just ran into this on an angular-cli project which is using Webpack 2.1.0-beta.24 and awesome-typescript-loader 2.2.4. Warning occurs when I export a string literal type from one file and import it in another.
I am still experiencing this issue while following the config example.
Everything works, but I get this warning:
105:93-104 "export 'SkypeConfig' was not found in './skype.config'
I noticed this warning occurs when there is more than one
export
in the file where theinterface
is declared… so isolating the interface in one file and moving everything else to it’s own file fixes the issue.Not sure why this is happening, but thankfully, no more warnings.
Heya all, just wanted to mention I looked into this further from the Angular CLI side and provided a comprehensive answer in angular/angular-cli#2034 (comment).
@mrchief Well yes, it’s correct syntax, but what I was saying is that you cannot use that syntax for destructuring out a value from an exported object.
From the example you linked to:
Even though the above export statement looks like an object, it is not, it’s two named exports. It’s equivalent to writing:
As you can have multiple named exports in a file, we have the following syntax which allow us to pick which exports that we want to import:
If you are using a default export to export an object, as in Pavel’s example:
Then you must use the default import statement:
This will give you the exported object on which you can call the f1 function:
So even though the named import statement looks like object destructuring, it is in fact not, and that is what is causing the confusion.
So for Pavel’s example to work without warning, both the import and exports must be either named or default, e.g.
or
Hope that make it clearer 🙂
Now its my turn to apologize @Markus-ipse ! I missed one significant detail earlier –
export default
vsexport {
. Yes I see the confusion now.Thanks for the detailed response. Would have not wasted your time if my eyes could read better.👁️