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

css-loader 4 compatibility requires documentation #46

Closed
davidhouweling opened this issue Aug 18, 2020 · 2 comments
Closed

css-loader 4 compatibility requires documentation #46

davidhouweling opened this issue Aug 18, 2020 · 2 comments

Comments

@davidhouweling
Copy link
Contributor

davidhouweling commented Aug 18, 2020

I've attempted to upgrade to to css-loader 4 in our local project but ran into the following error

ModuleNotFoundError: Module not found: Error: Can't resolve '~' in 'C:\git\test-project\src\styles'
    at C:\git\test-project\node_modules\webpack\lib\Compilation.js:925:10
    at C:\git\test-project\node_modules\webpack\lib\NormalModuleFactory.js:401:22
    at C:\git\test-project\node_modules\webpack\lib\NormalModuleFactory.js:130:21
    at C:\git\test-project\node_modules\webpack\lib\NormalModuleFactory.js:224:22
    at C:\git\test-project\node_modules\neo-async\async.js:2830:7
    at C:\git\test-project\node_modules\neo-async\async.js:6877:13
    at C:\git\test-project\node_modules\neo-async\async.js:2830:7
    at done (C:\git\test-project\node_modules\neo-async\async.js:2925:13)
    at C:\git\test-project\node_modules\webpack\lib\NormalModuleFactory.js:445:10
    at C:\git\test-project\node_modules\webpack\node_modules\enhanced-resolve\lib\Resolver.js:213:14
    at C:\git\test-project\node_modules\webpack\node_modules\enhanced-resolve\lib\Resolver.js:285:5
    at eval (eval at create (C:\git\test-project\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:15:1)
    at C:\git\test-project\node_modules\webpack\node_modules\enhanced-resolve\lib\UnsafeCachePlugin.js:44:7
    at C:\git\test-project\node_modules\webpack\node_modules\enhanced-resolve\lib\Resolver.js:285:5
    at eval (eval at create (C:\git\test-project\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:15:1)
    at C:\git\test-project\node_modules\webpack\node_modules\enhanced-resolve\lib\Resolver.js:285:5

I tracked it down to

const url = '~!!' + iconFontLoaderPath + '?' + JSON.stringify(options) + '!' + iconFontPlaceholderPath;

I thought the way to fix it is to tell css-loader@4 not to interpret ~!!:

          {
            loader: 'css-loader',
            options: {
              // number of loaders to process before css-loader (i.e. postcss, sass-loader)
              importLoaders: 2,
              url: (url) => {
                // iconfont-webpack-plugin requires css-loader to be filtered out
                return url.startsWith('~!!');
              },
            },
          },

However this makes the url not parse at all. Any idea how to solve this?

@davidhouweling
Copy link
Contributor Author

davidhouweling commented Aug 18, 2020

OK I think I found it: https://github.com/webpack-contrib/css-loader/blob/master/CHANGELOG.md#-breaking-changes

inline syntax was changed, please write ~ before the file request, i.e. rewrite url(~!!loader!package/img.png) to url(!!loader!~package/img.png)

I changed the local package in my node_modules folder so that the mentioned line is written as

const url = '!!' + iconFontLoaderPath + '?' + JSON.stringify(options) + '!~' + iconFontPlaceholderPath;

And it worked successfully.

@jantimon
Copy link
Owner

Hey @davidhouweling

you are right

const url = '~!!' + iconFontLoaderPath + '?' + JSON.stringify(options) + '!' + iconFontPlaceholderPath;

is causing the issues.. I am happy that the css-loader is finally removing the modules option 👍

jantimon pushed a commit that referenced this issue Aug 18, 2020
css-loader@4 introduced a breaking change which meant the use of `~` needs to be relocated from
before the `!!` to after the loader use + `!`

BREAKING CHANGE: this change requires css-loader@4 to work, earlier versions of css-loader should
use previous version

re #46
jantimon pushed a commit that referenced this issue Aug 19, 2020
css-loader@4 introduced a breaking change which meant the use of `~` needs to be relocated from
before the `!!` to after the loader use + `!`

BREAKING CHANGE: this change requires css-loader@4 to work, earlier versions of css-loader should
use previous version

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

No branches or pull requests

2 participants