NXGS warning of "export 'StateContext' was not found in '@ngxs/store'"

Viewed 592

Am using NWRL NX and one of the libraries is using NXGS (3.6.2) as a shared state library for the apps.

When running an application I am getting the warning export 'StateContext' was not found in '@ngxs/store and referencing the actions type of StateContext e.g. example function below:

@Action(FundListActions.Fetch)
fetch({ setState, getState, dispatch}: StateContext < StateModel > ) {
    const state = getState();
    setState({
        ...state,
        loaded: false,
        loading: true,
        error: null,
    });
}

The NXGS is running as expected, but am wondering how to fix this warning message

1 Answers

From https://github.com/TypeStrong/ts-loader/issues/653#issuecomment-390889335, found the following homegrown webpack plugin that fixes this error for me:

const ModuleDependencyWarning = require("webpack/lib/ModuleDependencyWarning")

module.exports = class IgnoreNotFoundExportPlugin {
  apply(compiler) {
    const messageRegExp = /export '.*'( \(reexported as '.*'\))? was not found in/
    function doneHook(stats) {
      stats.compilation.warnings = stats.compilation.warnings.filter(function(warn) {
        return !(warn instanceof ModuleDependencyWarning && messageRegExp.test(warn.message));
      })
    }
    if (compiler.hooks) {
      compiler.hooks.done.tap("IgnoreNotFoundExportPlugin", doneHook);
    } else {
      compiler.plugin("done", doneHook);
    }
  }
}

And my webpack.config.js for storybook:

const IgnoreNotFoundExportPlugin = require('./ignore_not_found_export_plugin');

module.exports = async({config, mode}) => {
   // ...

   config.plugins = config.plugins || [];
   config.plugins.push(new IgnoreNotFoundExportPlugin());

   return config;
}
Related