Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack resolver does not work when webpack exports a promise configuration #883

Open
justinanastos opened this issue Jun 28, 2017 · 3 comments

Comments

@justinanastos
Copy link
Contributor

As of webpack v2, the webpack configuration file can export a Promise: https://webpack.js.org/configuration/configuration-types/#exporting-a-promise.

The webpack resolver does not attempt to resolve that promise to use the configuration.

@st-sloth
Copy link
Contributor

I too came here for this. Then I dug deeper. And if I understand correctly, ESLint is designed to be very synchronous, so the rules can't be async. Thought I'm not sure whether plugins can have any async preparation step.

But settings['import/resolver'].webpack.config can be a config object, so it seems possible to have some kind of script that prints the webpack config and call it in the ESLint config via execSync or something.

However, in our case it was much easier to similarly "synchronize" async pre-build tasks to get rid of promising config and return it synchronously.

@ghost
Copy link

ghost commented Nov 15, 2018

If asynchronous part of your webpack config is not used in eslint, problem can be temporary fixed by extracting synchronous/static part in another file(webpack.sync-config.js for example).
Then you include it in eslint settings, and merge it in with async part in webpack.config.js by webpack-merge.

@apottere
Copy link

As a terrible, terrible workaround for when you have to have your async webpack config passed to eslint, you can "un-async" parts of your config by running another interpreter process with child_process and writing JSON to STDOUT, then reading that from your sync config. We didn't end up using this, but I figured I'd leave it here for anyone who's desperate for any solution at all:

// async-webpack.config.js
const load = async () => {
	// ...
	process.stdout.write(
		JSON.stringify({
			/* ... */
		})
	);
};

load().catch(e => {
	console.error(e);
	process.exitCode = 1;
});
// sync-webpack.config.js
const path = require('path');
const { spawnSync } = require('child_process');

const { stdout, stderr, status, signal, error } = spawnSync(process.argv0, [
	path.resolve(__dirname, 'async-webpack.config.js')
]);

// Error handling here (status/signal/error)...

const asyncConfig = JSON.parse(stdout);
// ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants