question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't resolve 'file-loader'

See original GitHub issue

When I run

yarn install --production
NODE_ENV=production ./node_modules/.bin/encore production

I get

Syntax Error: ModuleNotFoundError: Module not found: Error: Can't resolve 'file-loader' in '/var/www/vagrant.assurancevie.com/current'

But the module file-loader is installed. It’s not in node_modules but in node_modules/@symfony/webpack-encore/node_modules because I have another library requiring another version of file-loader.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
VincentLangletcommented, Apr 24, 2020

I tried to fix that by moving the resolving part in Encore, would you be able to test if that works for you?

$ yarn remove @symfony/webpack-encore
$ yarn add git://github.com/lyrkan/webpack-encore.git#loaders-resolving

Yes it works !

With no file-loader at the root of my node_modules image

0reactions
Lyrkancommented, Apr 24, 2020

When I don’t require it manually, I don’t have one at the root. I think it’s more a yarn bug than a webpack-encore bug, BUT I still considere there is a bug with encore, because webpack-encore should be able to use the hoisted dependency.

The issue is that Encore currently builds a Webpack config that looks like this:

{
  module: {
    rules: [
      {
        test: /\.(png|jpg|jpeg|gif|ico|svg|webp)$/,
        loader: 'file-loader'
      }
    ]
  }
}

This config is then used by Webpack that does the resolving of file-loader. Node checks if webpack has that dependency in its node_modules folder, then at the top-level. In your case both of them are missing and it has no reason to use the one from node_modules/@symfony/webpack-encore/node_modules.

I tried to fix that by moving the resolving part in Encore, would you be able to test if that works for you?

$ yarn remove @symfony/webpack-encore
$ yarn add git://github.com/lyrkan/webpack-encore.git#loaders-resolving
Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack: cannot resolve module 'file-loader' - Stack Overflow
Error: Module not found : Can't resolve 'url-loader'. Fixed by installing url-loader , ex: run 'npm install url-loader --save-dev'.
Read more >
file-loader - npm
The file-loader resolves import / require() on a file into a url and emits the file into the output directory.
Read more >
Webpack: cannot resolve module 'file-loader' - iTecNote
When I try to build SASS file with webpack, I got the following error: Module not found: Error:Cannot resolve module 'file-loader'.
Read more >
can't resolve 'file-loader' | The AI Search Engine You Control
As @silvenon said in his comment: Do you have file-loader installed? yes file-loader was installed but broken, and my issue has been solved...
Read more >
sass-loader - webpack - JS.ORG
Webpack provides an advanced mechanism to resolve files. ... CSS on to the css-loader , all urls must be relative to the entry-file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found