-
-
Notifications
You must be signed in to change notification settings - Fork 608
Option to ignore not found modules/URLs #455
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
Comments
@Aleksanderis It's depending on general usage, if it is possible to just display warnings and the build succees and works this would be a good idea. On the oher hand we already have a ton of url and @import releated issues because of the ambiguity of the resolver and trying to make it saner in the upcoming |
@michael-ciniawsky , sorry I'm quite new to webpack itself, and completely know-nothing yet in terms how webpack plugins/loaders are written inside. I didn't want to blame anyone, just was curious how easy it could be or couldn't be at all implemented.;) But.. are you saying that it's actually not Do I understand correctly how it works: |
@Aleksanderis Yes and no 😛 entry.js import lib from 'lib' // Parser => Resolver => Tapable(Core Plugins, Plugins)
import css from './style.css' // Parser => Resolver => Tapable(Core Plugins(e.g Loader(s)), Plugins)
import component from './component' // Parser => Resolver => Tapable(Core Plugins, Plugins)
... loader.js module.exports = function (source, map) {
console.log(this) // ~.context, ~.resource, ~.resourcePath ~.resolve => Resolver + others
...transform(source, map)
return this.async(Error, source, map)
}
Yep right this is the webpack Resolver I was referring to. It will provide metadata for webpack Loaders after resolving the module (see above)
The webpack Resolver and mainly a Core Plugin called webpack.config.js {
module: { // => Settings for Parser, Resolver, Module Factory
rules: [
{
test: /\.css$/,
use: { loader: 'css-loader' }
}
]
}
|
I'm also facing this issue. Currently what I'm planning to do is resolve it by making a dummy image and using the alias function to resolve to the dummy image. Maybe this could either be a feature where it simply warns about unresolved files, or even where you can specify the URLs to ignore as per the alias syntax? |
I don't think I could state it better. This feature would be great -- I have the exact same use case. I would prefer if Webpack handled the situation gracefully. Instead of exploding, just don't resolve the imports, and create a CSS file I can use. In this particular case, the fact that modules don't resolve does not matter. |
To anyone who might still be looking for a workaround, instead of processing these 'bad' CSS files (ones that have const Styles = require('!raw-loader!mystyles.css');
// later in my React component implementation
<style dangerouslySetInnerHTML={{__html: Styles}} /> It doesn't achieve the same goal as this issue (e.g., if you're extracting your CSS, this CSS will end up instead in your JS bundle), but it gets the job done. |
Would love a solution for this. |
Alternatively, what would be a resolver-for-not-founds-loader look like? all I found in docs, is mapping requests filenames to different filenames, not to sources themselves (meaning one could do |
@michael-ciniawsky when the fix will be released? |
I need this fix too |
@tomasdev thanks for tip! Now my solution is next: const fs = require('fs'); ... module: {
rules: [{
test: /\.css$/,
use: [
{
loader: 'css-loader',
options: {
url (url) {
return fs.existsSync(url)
}
}
}
]
}
} It`s works brilliant for me) |
Hi, I found that using Webpack's ignorePlugin was even easier to use. However, I was sort of hoping that my conditional checks for dependencies would be respected:
Sometimes I list dependencies as optional, so they won't always be packaged. Currently, webpack will throw an error and won't let my code be the one to handle it. Is it possible that I'm missing something or perhaps my design approach is flawed? |
In case anyone else needs a variant on @olytv's solution: {
test: function(url) {
var path = 'file.js'
if (fs.existsSync(path)) {
return require.resolve(path)
} else {
return false
}
},
use: 'imports-loader?this=>window'
}, |
Do you want to request a feature or report a bug?
It would be good to have an option to skip not found URLs instead of throwing "Module not found" errors.
It might be just a warning instead of critical error, or just skipped.
Ignoring all URLs and @imports, which is already supported - is not an option, since it's too global.
What is the current behavior?
When URL is not found it throws the error in following format:
This error eventually fails the whole webpack build.
What is the expected behavior?
If some options is enabled, such error becomes not critical and build is not marked as failed.
If this is a feature request, what is motivation or use case for changing the behavior?
Motivation is that when you rely on third-party library you cannot be sure they will include all files referenced in their
vendor.css
. We are forced (corporate branding stuff) to rely on some internal (but still third-party library - i.e. different team responsibility), which works following some strange bureaucracy workflow and bad publishing practices. So not including all referenced files - is a common case..Please mention other relevant information such as your webpack version, Node.js version and Operating System.
Would it be possible to implement such feature or are there any blockers why it wasn't made already so?
Or maybe there are other ways to achieve same thing?
The text was updated successfully, but these errors were encountered: