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

Add notice / warning when build fails and resolve.extensions is missing a leading dot, (developer experience improvement) #11695

Closed
Tracked by #17122
yaronuliel opened this issue Oct 15, 2020 · 4 comments · Fixed by #16807

Comments

@yaronuliel
Copy link

yaronuliel commented Oct 15, 2020

Feature request

The name of the configuration resolve.extensions is not clear enough about the fact that the extensions should start with . (e.g. ['.js', '.jsx'] and not ['js', 'jsx'])

The docs are OK, and this is quite a silly thing - until you find yourself trying to review every piece of a webpack config file for errors and keep getting failed builds

What is the expected behavior?
When a build fails (to prevent warning in cases where the extension shouldn't start with a dot) - if one of the extension in the configuration resolve.extensions does not start with a dot - show a warning or a hint (something like - Did you mean '.js'instead of'js' in resolve.extensions?

I'm not familiar enough with the guts of webpack, but, if it is also possible to check whether this change would have fix the issue that caused the build fail - be more explicit with the warning (e.g. when a resolver fails to find a file with listed extension - try adding dot if it is missing, and if it finds a file - show a more specific warning about that).

What is motivation or use case for adding/changing the behavior?
I just lost 1.5 hours debugging a webpack configuration, and after remove and installing every plugin/loader that I installed million times - I realised that this **** dot was the problem (though the error didn't suggest anything close to that)

How should this be implemented in your opinion?
In a developer friendly way!
see response for "What is the expected behavior?"

Are you willing to work on this yourself?
yes, but I will probably need some guidance about where to start

@yaronuliel yaronuliel changed the title Add notice / warning when build failed and resolve.extensions missing a leading dot for better developer experience Add notice / warning when build fails and resolve.extensions missing a leading dot, (developer experience improvement) Oct 15, 2020
@yaronuliel yaronuliel changed the title Add notice / warning when build fails and resolve.extensions missing a leading dot, (developer experience improvement) Add notice / warning when build fails and resolve.extensions is missing a leading dot, (developer experience improvement) Oct 15, 2020
@sokra
Copy link
Member

sokra commented Oct 15, 2020

Send a PR

Here is similar code and also the place where this need to be added:

resolveResource(
contextInfo,
context,
unresolvedResource,
resolver,
resolveContext,
callback
) {
resolver.resolve(
contextInfo,
context,
unresolvedResource,
resolveContext,
(err, resolvedResource, resolvedResourceResolveData) => {
if (err) {
if (resolver.options.fullySpecified) {
resolver
.withOptions({
fullySpecified: false
})
.resolve(
contextInfo,
context,
unresolvedResource,
resolveContext,
(err2, resolvedResource) => {
if (!err2 && resolvedResource) {
const resource = parseResource(
resolvedResource
).path.replace(/^.*[\\/]/, "");
err.message += `
Did you mean '${resource}'?
BREAKING CHANGE: The request '${unresolvedResource}' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.`;
}
callback(err);
}
);
return;
}
}
callback(err, resolvedResource, resolvedResourceResolveData);
}
);
}

yaronuliel added a commit to yaronuliel/webpack that referenced this issue Oct 17, 2020
Add a warning while user configured resolve.extensions without a leading dot (e.g. ["js", "jsx"]), and a module resolution fails because of that
yaronuliel added a commit to yaronuliel/webpack that referenced this issue Oct 17, 2020
Add a warning while user configured resolve.extensions without a leading dot (e.g. ["js", "jsx"]), and a module resolution fails because of that
yaronuliel added a commit to yaronuliel/webpack that referenced this issue Oct 17, 2020
Add a warning while user configured resolve.extensions without a leading dot (e.g. ["js", "jsx"]), and a module resolution fails because of that
@webpack-bot
Copy link
Contributor

This issue had no activity for at least three months.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@snitin315
Copy link
Member

Bump

@webpack-bot
Copy link
Contributor

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

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

Successfully merging a pull request may close this issue.

6 participants