<p dir="auto"><strong>Do you want to request a <em>feature</em> or report a <em>bug</em>?</strong><br>
Feature</p>
<p dir="auto"><strong>What is the current behavior?</strong><br>
If multiple rules match a module, I believe either the loaders are applied serially or only loaders from the first-matched rule processes the file.</p>
<p dir="auto"><strong>What is the expected behavior?</strong><br>
I'd like to be able to process the same module multiple times, possibly via separate rules. This doesn't necessarily need to be asynchronous.</p>
<p dir="auto">There was a loader that helped with this once, but it no longer appears relevant in webpack 2/3: <a href="https://github.com/webpack-contrib/multi-loader">https://github.com/webpack-contrib/multi-loader</a>; for loaders like ExtractTextPlugin, no file is output.</p>
<p dir="auto">One implementation of this might be allowing us to configure a rule to only apply for certain entries; e.g.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="config = {
  entry: { main: 'index.js', vendor: 'vendor.js' },
  module: { rules: [ { test: (file, entry) =&gt; file === 'test.css' &amp;&amp; entry === 'main', use: [ ... ] } ] }
} "><pre class="notranslate"><span class="pl-s1">config</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
  <span class="pl-c1">entry</span>: <span class="pl-kos">{</span> <span class="pl-c1">main</span>: <span class="pl-s">'index.js'</span><span class="pl-kos">,</span> <span class="pl-c1">vendor</span>: <span class="pl-s">'vendor.js'</span> <span class="pl-kos">}</span><span class="pl-kos">,</span>
  <span class="pl-c1">module</span>: <span class="pl-kos">{</span> <span class="pl-c1">rules</span>: <span class="pl-kos">[</span> <span class="pl-kos">{</span> <span class="pl-en">test</span>: <span class="pl-kos">(</span><span class="pl-s1">file</span><span class="pl-kos">,</span> <span class="pl-s1">entry</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-s1">file</span> <span class="pl-c1">===</span> <span class="pl-s">'test.css'</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">entry</span> <span class="pl-c1">===</span> <span class="pl-s">'main'</span><span class="pl-kos">,</span> <span class="pl-c1">use</span>: <span class="pl-kos">[</span> ... <span class="pl-kos">]</span> <span class="pl-kos">}</span> <span class="pl-kos">]</span> <span class="pl-kos">}</span>
<span class="pl-kos">}</span> </pre></div>
<p dir="auto">Or perhaps we can just specify a rule to apply in "parallel", for any overlapping rules.</p>
<p dir="auto"><strong>If this is a feature request, what is motivation or use case for changing the behavior?</strong><br>
Lots of use cases for this; one might be to process a stylesheet in different ways, and saving them as separate files via ExtractTextPlugin.</p>
<h1 dir="auto">Bug report</h1>




<p dir="auto"><strong>What is the current behavior?</strong><br>
When packing for the second time, webpack reports 'Restoring failed for ResolverCachePlugin'.<br>
e.g.</p>
<p dir="auto"> [webpack.cache.PackFileCacheStrategy] Restoring failed for ResolverCachePlugin|normal|dependencyType=|commonjs|path=|/Users/keboliu/vscode-shortcut/portal-h5-node/src/views/teleclinict/booking/case-info|request=|@/lib/utils.js from pack: SyntaxError: Cannot use import statement outside a module<br>
 (during deserialization of Array)<br>
 (during deserialization of webpack/lib/NormalModule)<br>
 (during deserialization of Map)<br>
 (during deserialization of webpack/lib/cache/PackFileCacheStrategy PackContentItems)<br>
 [webpack.cache.PackFileCacheStrategy] Restoring failed for ResolverCachePlugin|normal|dependencyType=|commonjs|path=|/Users/keboliu/vscode-shortcut/portal-h5-node/src/views/teleclinict/booking/case-info|request=|../components/case-info-card.vue from pack: SyntaxError: Cannot use import statement outside a module<br>
 (during deserialization of Array)<br>
 (during deserialization of webpack/lib/NormalModule)<br>
 (during deserialization of Map)<br>
 (during deserialization of webpack/lib/cache/PackFileCacheStrategy PackContentItems)<br>
 [webpack.cache.PackFileCacheStrategy] Restoring failed for ResolverCachePlugin|normal|dependencyType=|commonjs|path=|/Users/keboliu/vscode-shortcut/portal-h5-node/src/views/teleclinict/booking/addlocaldoctor|request=|wand-ui/es/components/search/style from pack: SyntaxError: Cannot use import statement outside a module<br>
 (during deserialization of Array)<br>
 (during deserialization of webpack/lib/NormalModule)<br>
 (during deserialization of Map)<br>
 (during deserialization of webpack/lib/cache/PackFileCacheStrategy PackContentItems)</p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong><br>
I cannot provide the specific steps, because this is a upgrade attempt, webpack4 to 5 via vue2.6 ssr.<br>
I can provide webpack configuration segment. Actually I've been trying to see if babel configuration going wrong.</p>
<p dir="auto">/<strong>webpack base config</strong>***/<br>
const baseConfig = {<br>
mode: isProd ? 'production' : 'development',<br>
context: path.resolve(__dirname, '../'),<br>
output: {<br>
path: path.resolve(__dirname, '../dist'),<br>
publicPath: config.staticPublicPath || '/dist/',<br>
filename: 'js/[name].[chunkhash].js',<br>
assetModuleFilename: '[name].[contenthash].[ext]'<br>
},<br>
cache:  {<br>
type: 'filesystem',<br>
buildDependencies: {<br>
config: [<br>
<code class="notranslate">${__dirname}/</code>,<br>
path.join(__dirname, '../package.json')<br>
]<br>
},<br>
version: '1.0.0'<br>
},<br>
watchOptions: {<br>
aggregateTimeout: 500,<br>
poll: 1000<br>
},<br>
stats: 'errors-only',<br>
resolve: {<br>
symlinks: false,<br>
alias: {<br>
'~': path.resolve(__dirname, '..'),<br>
'@': path.resolve(__dirname, '../src'),<br>
'public': path.resolve(__dirname, '../public'),<br>
'assets': path.resolve(__dirname, '../src/assets')<br>
},<br>
extensions: ['.js', '.vue', '.less'],<br>
fallback: {<br>
'os': require.resolve('os-browserify/browser')<br>
},<br>
},<br>
module: {<br>
noParse: [/es6-promise.js$/, /lottie-web/, /pdfjs-dist/, /agentkeepalive/], // avoid webpack shimming process<br>
rules: [<br>
{<br>
test: /.vue$/,<br>
loader: 'vue-loader',<br>
options: vueLoaderConfig<br>
},<br>
{<br>
test: /.js$/,<br>
loader: 'babel-loader',<br>
options: {<br>
cacheDirectory: true<br>
},<br>
exclude: /node_modules.(?!(dom7|ssr-window|swiper).).<em>/<br>
},<br>
{<br>
test: /.(png|jpg|gif|svg)$/,<br>
type: 'asset'<br>
},<br>
{<br>
test: /.(eot|ttf|woff|woff2)$/,<br>
type: 'asset'<br>
}<br>
]<br>
},<br>
performance: {<br>
maxEntrypointSize: 300000,<br>
hints: isProd ? 'warning' : false<br>
},<br>
optimization: {<br>
minimizer: isProd ? [<br>
new TerserPlugin({<br>
extractComments: false,<br>
parallel: true,<br>
terserOptions: {<br>
warnings: false<br>
}<br>
}),<br>
new CssMinimizerPlugin()<br>
] : []<br>
},<br>
plugins: isProd ? [] : [<br>
new StyleLintPlugin({<br>
extensions: ['css', 'less'],<br>
files: ['src/styles/</em>.l?(e|c)ss', 'src/views-local/<strong>/*.vue', 'src/views/</strong>/<em>.vue', 'src/components/**/</em>.vue'],<br>
failOnError: false<br>
}),<br>
new FriendlyErrorsPlugin()<br>
]<br>
}</p>
<p dir="auto">!isProd &amp;&amp; baseConfig.module.rules.unshift({<br>
test: /.(js|vue)$/,<br>
loader: 'eslint-loader',<br>
enforce: 'pre',<br>
exclude: /node_modules/,<br>
include: [path.resolve(__dirname, '../config'), path.resolve(__dirname, '../src'), path.resolve(__dirname, '../test')],<br>
options: {<br>
formatter: require('eslint-friendly-formatter'),<br>
emitWarning: true,<br>
cache: true,<br>
quiet: true,<br>
errorStack: false<br>
}<br>
})</p>
<p dir="auto">baseConfig.plugins.push(<br>
new webpack.ProvidePlugin({<br>
process: 'process/browser.js'<br>
})<br>
)<br>
baseConfig.plugins.push(new VueLoaderPlugin())<br>
baseConfig.plugins.push(new CopyWebpackPlugin({<br>
patterns: [<br>
{ from: 'node_modules/pdfjs-dist/build/pdf.worker.min.js' },<br>
{ from: 'node_modules/pdfjs-dist/cmaps', to: 'cmaps' }<br>
]<br>
}))</p>
<p dir="auto">module.exports = baseConfig<br>
/<strong>webpack base config</strong>***/</p>
<p dir="auto">/<strong>.babelrc.js</strong>****/<br>
module.exports = {<br>
presets: [<br>
"@babel/preset-flow",<br>
[<br>
"@babel/preset-env",<br>
{<br>
"modules": "commonjs",<br>
"useBuiltIns": "usage",<br>
"corejs": 3,<br>
targets: {<br>
browsers: ['ios &gt;= 7', 'android &gt;= 4.0.3']<br>
}<br>
}<br>
]<br>
],<br>
sourceType: 'unambiguous',<br>
plugins: [<br>
'@babel/plugin-transform-runtime',<br>
"@babel/plugin-syntax-dynamic-import",<br>
[<br>
"import",<br>
{<br>
"libraryName": "wand-ui",<br>
"libraryDirectory": "es/components",<br>
"style": true,<br>
"camel2DashComponentName": true,<br>
"customName": function(name){<br>
return <code class="notranslate">wand-ui/es/components/${name.substr(3)}</code><br>
}<br>
},<br>
"wand-ui"<br>
],<br>
[<br>
"import",<br>
{<br>
"libraryName": "@weiyi/wand-ui-user",<br>
"libraryDirectory": "lib/components",<br>
"style": (name) =&gt; {<br>
return <code class="notranslate">${name}/index.css</code>;<br>
},<br>
"camel2DashComponentName": true,<br>
"customName": function (name) {<br>
return <code class="notranslate">@weiyi/wand-ui-user/lib/components/${name.substr(8)}</code><br>
}<br>
},<br>
"@weiyi/wand-ui-user"<br>
],<br>
[<br>
"component",<br>
{<br>
"libraryName": "@weiyi/wand-ui",<br>
"styleLibrary": {<br>
"name": "theme-chalk",<br>
"base": true<br>
},<br>
"libDir": "lib",<br>
"root": "wand-ui"<br>
}<br>
]<br>
],<br>
env: {<br>
"test": {<br>
"presets": [<br>
"@babel/preset-env"<br>
],<br>
"plugins": [<br>
[<br>
"babel-plugin-webpack-aliases",<br>
{<br>
"config": "./build/webpack.base.config.js",<br>
"findConfig": true<br>
}<br>
]<br>
]<br>
}<br>
}<br>
}<br>
/<strong>.babelrc.js</strong>****/</p>






<p dir="auto"><strong>What is the expected behavior?</strong><br>
wevpack restoring works.</p>


<p dir="auto"><strong>Other relevant information:</strong><br>
npx webpack-cli info                                                                                                                                                                                                                                                                       ⏎<br>
System:<br>
OS: macOS 12.5<br>
CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz<br>
Memory: 31.57 MB / 16.00 GB<br>
Binaries:<br>
Node: 14.15.4 - /usr/local/bin/node<br>
npm: 8.1.2 - /usr/local/bin/npm<br>
Browsers:<br>
Chrome: 104.0.5112.79<br>
Chrome Canary: 106.0.5246.0<br>
Firefox: 100.0<br>
Safari: 15.6<br>
Packages:<br>
babel-loader: ^8.2.5 =&gt; 8.2.5<br>
babel-plugin-webpack-aliases: ^1.1.3 =&gt; 1.1.3<br>
copy-webpack-plugin: ^11.0.0 =&gt; 11.0.0<br>
css-loader: ^6.7.1 =&gt; 6.7.1<br>
css-minimizer-webpack-plugin: ^4.0.0 =&gt; 4.0.0<br>
eslint-loader: ^4.0.2 =&gt; 4.0.2<br>
friendly-errors-webpack-plugin: ^1.7.0 =&gt; 1.7.0<br>
html-webpack-include-assets-plugin: ^1.0.10 =&gt; 1.0.10<br>
html-webpack-plugin: ^5.5.0 =&gt; 5.5.0<br>
intelli-espower-loader: ^1.1.0 =&gt; 1.1.0<br>
istanbul-instrumenter-loader: ^3.0.1 =&gt; 3.0.1<br>
less-loader: ^7.3.0 =&gt; 7.3.0<br>
null-loader: ^4.0.1 =&gt; 4.0.1<br>
postcss-loader: ^7.0.1 =&gt; 7.0.1<br>
stylelint-webpack-plugin: ^3.3.0 =&gt; 3.3.0<br>
terser-webpack-plugin: ^5.3.3 =&gt; 5.3.5<br>
thread-loader: ^3.0.4 =&gt; 3.0.4<br>
vue-loader: ^15.10.0 =&gt; 15.10.0<br>
webpack: 5.56.0 =&gt; 5.56.0<br>
webpack-bundle-analyzer: ^4.5.0 =&gt; 4.5.0<br>
webpack-cli: 4.9.1 =&gt; 4.9.1<br>
webpack-dev-middleware: ^5.3.3 =&gt; 5.3.3<br>
webpack-hot-middleware: ^2.25.1 =&gt; 2.25.2<br>
webpack-merge: 5.8.0 =&gt; 5.8.0<br>
webpack-node-externals: ^3.0.0 =&gt; 3.0.0<br>
webpack-sources: ^3.2.3 =&gt; 3.2.3</p>