webpack icon indicating copy to clipboard operation
webpack copied to clipboard

Strange warning stating that export does not exist when it does

Open domehead100 opened this issue 8 years ago • 74 comments

Bug report

What is the current behavior?

Not sure if this is a problem with a loader or webpack itself, but on a project that is using typescript, I'm getting a warning:

    WARNING in ./React/src/components/_shared/form/form-model.ts
    17:0-39 "export 'IValidation' was not found in '_types/IValidation'"
        at HarmonyExportImportedSpecifierDependency._getErrors (C:\project\node_modules\webpack\lib\dependencies\HarmonyExportImportedSpecifierDependency.js:352:11)
        at HarmonyExportImportedSpecifierDependency.getWarnings (C:\project\node_modules\webpack\lib\dependencies\HarmonyExportImportedSpecifierDependency.js:299:15)
        at Compilation.reportDependencyErrorsAndWarnings (C:\project\node_modules\webpack\lib\Compilation.js:985:24)
        at Compilation.finish (C:\project\node_modules\webpack\lib\Compilation.js:817:9)
        at hooks.make.callAsync.err (C:\project\node_modules\webpack\lib\Compiler.js:479:17)
        at _done (eval at create (C:\project\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:9:1)
        at _err0 (eval at create (C:\project\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:20:22)
        at _addModuleChain (C:\project\node_modules\webpack\lib\Compilation.js:758:12)
        at processModuleDependencies.err (C:\project\node_modules\webpack\lib\Compilation.js:697:9)
        at _combinedTickCallback (internal/process/next_tick.js:131:7)
        at process._tickCallback (internal/process/next_tick.js:180:9)

However, the file in question _types/IValidation, is imported in numerous other files without any warnings being emitted related to those other files that are also importing IValidation from _types/IValidation.

The contents of the file are simple, and there is an "export interface IValidation" in the file:

export enum ValidationType {
    Required,
    Min,
    Max,
    MinLength,
    MaxLength,
}

export interface IValidation {
    validationType: ValidationType;
    errorMessage?: string;
    minValue?: number;
    maxValue?: number;
    maxLength?: number;
    minLength?: number;
}

We do have our "src" directory set as a module resolution root in the resolve section of our webpack config, but I also tried importing the file with a relative path and still get the warning.

I am kind of wondering if this is related to typescript. We are using ts-loader, but we have it doing type checking only and are doing transpiling with babel.

If the current behavior is a bug, please provide the steps to reproduce. Not sure since I get the warning due to the import of the file in question in one file but not due to several other files that also import the same interface from the same file.

What is the expected behavior? It should not issue a warning about a missing export if the export clearly exists.

Other relevant information: webpack version: 4.8.3 Node.js version: 8.9.1 Operating System: Windows 10 Additional tools: webpack-cli 2.1.3

domehead100 avatar May 23 '18 16:05 domehead100

Perhaps it would be awesome if you could create a simple project that would reproduce your bug and upload on github.

tryzniak avatar May 26 '18 10:05 tryzniak

Interfaces no longer exist after transpiling. For webpack the export doesn't exist.

sokra avatar May 26 '18 14:05 sokra

True, typescript would remove the interfaces but should also remove the imports.

I'm not sure where the warning is coming from (maybe not from webpack itself).

I'll do some testing and see if I can figure it out.

We never had this happen on webpack 3.10 (were trying to upgrade to 4.8.3).

domehead100 avatar May 26 '18 18:05 domehead100

I guess, it's related to ts-loader then ...

Legends avatar May 26 '18 19:05 Legends

@johnnyreilly Can you help us on this?

ooflorent avatar Jun 05 '18 11:06 ooflorent

Here is a temp solution: https://github.com/TypeStrong/ts-loader/issues/653#issuecomment-390889335

rgripper avatar Jun 28 '18 00:06 rgripper

The temp solution suggested by @rgripper should work. I'd be open to baking this into ts-loader since it seems to have bitten a few people... Would anyone like to submit a PR?

johnnyreilly avatar Jun 28 '18 04:06 johnnyreilly

On the linked thread I've put details, a suggestion for implementation and an offer of help if someone wants to submit a PR. Let's see what happens! :heart: :sunflower:

johnnyreilly avatar Jun 28 '18 05:06 johnnyreilly

We are facing the same issue using babel-loader with https://babeljs.io/docs/en/babel-plugin-transform-typescript

sarod avatar Oct 19 '18 09:10 sarod

The same problem here for TS types/interfaces after migrating from WP3 to WP4, multiple warnings:

VM606323 index.js:151 ./apps/client/state.ts 3:0-82
"export 'ChartElement' was not found in './cycles/ChartArea/chartElements'

I don't use ts-loader or anything special just simple loader:

const ts = require('typescript')
const tsconfig = require('tsconfig')

const compilerOptions = tsconfig.loadSync(process.cwd()).config.compilerOptions

module.exports = function (source) {  
  const result = ts.transpile(source, { ...compilerOptions, ...this.query })
  return result
}

So it is not a problem of ts-loader

wclr avatar Nov 17 '18 22:11 wclr

Hello. I create simple plugin for suppress this error. 👨‍💻

https://github.com/igorkamyshev/ignore-not-found-export-plugin

igorkamyshev avatar Jan 22 '19 12:01 igorkamyshev

FWIW I only just started seeing this issue today in one of my react/redux/saga projects after refactoring my code layout from:

PageSagas.js
PageActions.js
PageReducers.js

to

feature-A/sagas.js
feature-A/actions.js
feature-A/reducers.js
feature-B/sagas.js
feature-B/actions.js
feature-B/reducers.js
PageSagas.js
PageActions.js
PageReducers.js

to try to organize the growing project a bit more.

Not sure if the duplicate filenames across feature folders could have anything to do with this weird warning display issue.

And because more detail doesn't hurt with debugging, in my particular case the exported function names don't match the filenames right now. They currently look like:

// feature-A/reducers.js :
export default function featureAReducer(...) {}

instead of

// feature-A/reducers.js :
export default function reducers(...) {}

Hope this helps with the debugging. In the meantime, @igorkamyshev 's plugin looks good.

Webpack version info:

  • Pulled in via "laravel-mix": "^4.0.14" , which (seems to be using)[https://github.com/JeffreyWay/laravel-mix/blob/v4.0.14/package.json#L63]
  • "webpack": "^4.27.1"

anjunatl avatar Feb 12 '19 22:02 anjunatl

Update: Some of the files the warnings fired for had both export function X and export default function X snippets in them, some just had one export default function X snippet. All of the warnings went away when I removed all of the default keywords. Hope this helps.

anjunatl avatar Feb 12 '19 23:02 anjunatl

@anjunatl, yours seems to be a different issue. This one is about exporting interfaces in typescript and is well understood. There is a comment somewhere explaining it really well, but I currently can not find it. Basically the typescript compiler emits no code for interfaces, so webpack can not find them in the compiled module; except when a module consists of only interfaces. In that case the module will end up completely empty and then webpack will not investigate the exports.

You should probably create a new issue for your problem.

bodograumann avatar Feb 13 '19 08:02 bodograumann

@igorkamyshev somehow, no matter using stats or your plugin, I'm still getting errors :/

natew avatar Apr 18 '19 03:04 natew

@igorkamyshev somehow, no matter using stats or your plugin, I'm still getting errors :/

Sorry, it was deprecated. =(

igorkamyshev avatar Apr 19 '19 06:04 igorkamyshev

Is there currently a way to suppress these errors? I'm not having any luck with Webpack's stat config.

elliotbonneville avatar May 08 '19 19:05 elliotbonneville

For client at least you can: devServer: { clientLogLevel: 'error' } }

On Wed, May 8, 2019 at 12:55 PM Elliot Bonneville [email protected] wrote:

Is there currently a way to suppress these errors? I'm not having any luck with Webpack's stat config.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/webpack/webpack/issues/7378#issuecomment-490627198, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAC6RCCN7MRL2BT4JWE3M3PUMV2ZANCNFSM4FBLAUOQ .

natew avatar May 08 '19 19:05 natew

Thanks, @natew. Is there anything more specific? I'd like to leave other warnings intact.

elliotbonneville avatar May 08 '19 20:05 elliotbonneville

Maybe this is not a bug, its a feature! (tm) :) See: https://github.com/Microsoft/TypeScript/issues/28481

When you export your TS interfaces/types in such a style so that it comply with TS's isolatedModules=true, then you won't get these webpack warnings.

import { State } from './interfaces';
export type State = State;

MarekLacoAXA avatar May 15 '19 12:05 MarekLacoAXA