Skip to content

Using webpack alias false breaks build #1291

Closed
@mmarton

Description

@mmarton
  • Operating System: linux mint 20
  • Node Version: 15.11
  • NPM Version: 7.6 (but I use yarn: 1.22.5)
  • webpack Version: 5.33.2
  • css-loader Version: 5.2.3

Expected Behavior

If I alias something to false in webpack config to not to get resolved, the build breaks. Expected to work.
https://webpack.js.org/configuration/resolve/#resolvealias

null-loader is deprecated in webpack 5. use alias: { xyz$: false } or absolute path alias: {[path.resolve(__dirname, './path/to/module')]: false }

Actual Behavior

ERROR in ./index.scss
Module build failed (from ./node_modules/css-loader/dist/cjs.js):
TypeError: request.split is not a function
    at stringifyRequest (/home/mm/PhpstormProjects/css-loader-poc/node_modules/loader-utils/lib/stringifyRequest.js:16:28)
    at Object.urlHandler (/home/mm/PhpstormProjects/css-loader-poc/node_modules/css-loader/dist/index.js:95:60)
    at OnceExit (/home/mm/PhpstormProjects/css-loader-poc/node_modules/css-loader/dist/plugins/postcss-url-parser.js:324:30)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at async LazyResult.runAsync (/home/mm/PhpstormProjects/css-loader-poc/node_modules/postcss/lib/lazy-result.js:388:13)
    at async Object.loader (/home/mm/PhpstormProjects/css-loader-poc/node_modules/css-loader/dist/index.js:139:14)

Code

const path = require('path');
module.exports = {
    entry: './index.css',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'build.css'
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                use: {loader: 'css-loader'}
            }
        ]
    },
    resolve: {
        alias: {'/logo.png': false}
    }
}
.logo {
    background-image: url(/logo.png);
}

How Do We Reproduce?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions