Skip to content

Commit

Permalink
Resolve loaders relative to next-images
Browse files Browse the repository at this point in the history
This fixes an issue where url-loader cannot be resolved when using
strict package managers such as pnpm or yarn pnp:

    Module not found: Can't resolve 'url-loader' in '/path/to/project'

Most users don't notice this because npm and yarn by default hoist
transitive dependencies to the root, so url-loader can be resolved from
the app's webpack config:

    node_modules/
      next-images/
      url-loader/
      file-loader/

However, more strict package managers do not perform hoisting:

    node_modules/
      next-images/
        node_modules/
          url-loader/
          file-loader/

So 'url-loader' cannot be resolved from the root.
  • Loading branch information
elliottsj committed Jun 10, 2019
1 parent 158a319 commit 558e646
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -15,10 +15,10 @@ module.exports = (nextConfig = {}) => {
exclude: nextConfig.exclude,
use: [
{
loader: "url-loader",
loader: require.resolve("url-loader"),
options: {
limit: nextConfig.inlineImageLimit,
fallback: "file-loader",
fallback: require.resolve("file-loader"),
publicPath: `${nextConfig.assetPrefix}/_next/static/images/`,
outputPath: `${isServer ? "../" : ""}static/images/`,
name: "[name]-[hash].[ext]"
Expand Down

0 comments on commit 558e646

Please sign in to comment.