Home

Issue: 1862

Using query parameters in require statements: require('~/assets/something?test=true')

[issue link]

Hi, I’ve encountered an issue I think might be due to the magic import handling for assets. Using nuxt 1.0.0-rc11.

I’m using responsive-loader to resize images from assets.

If I configure the loader in nuxt.config.js like this:

 extend: (config, { isClient }) => {
      const urlLoader = config.module.rules.find(
        rule => rule.loader === 'url-loader'
      );
      urlLoader.test = /\.(gif)$/;

      config.module.rules.push({
        test: /\.(jpe?g|png)$/i,
        loader: 'responsive-loader',
        options: {
          placeholder: true,
          placeholderSize: 20,
          sizes: [300]
        }
      });
    },

…then this works:

require(`~/assets/images/${item.key}/${i}.png`)

However, if I add a query parameter:

require(`~/assets/images/${item.key}/${i}.png?sizes[]=300`)

I get:

 Cannot find module "~/assets/images" 

Is this due to import handling, or have I misconfigured the loader?

This question is available on Nuxt.js community (#c1673)