<p dir="auto"><strong>I'm submitting a bug report</strong><br>
<strong>Webpack version:</strong><br>
1.13.2</p>
<p dir="auto"><strong>Please tell us about your environment:</strong><br>
Windows 7</p>
<p dir="auto"><strong>Current behavior:</strong><br>
For the following code snippet</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="        require.ensure(
            ['./module'],
            (syncedRequire) =&gt; {
                doSomething(syncedRequire('./module'));
            },
            'module');"><pre class="notranslate"><code class="notranslate">        require.ensure(
            ['./module'],
            (syncedRequire) =&gt; {
                doSomething(syncedRequire('./module'));
            },
            'module');
</code></pre></div>
<p dir="auto">webpack generates this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="	        __webpack_require__.e/* nsure */(1, function (syncedRequire) {
	            doSomething(syncedRequire('./module'));
	        });"><pre class="notranslate"><code class="notranslate">	        __webpack_require__.e/* nsure */(1, function (syncedRequire) {
	            doSomething(syncedRequire('./module'));
	        });
</code></pre></div>
<p dir="auto">This is invalid, because syncedRequire will be the <strong>webpack_require</strong> function, and that function expects a number instead of a string. For the string it'll fail.</p>
<p dir="auto"><strong>Expected/desired behavior:</strong><br>
One solution is to remove the callback argument that won't be required anyway, if you're implementing the following code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="        require.ensure(
            ['./module'],
            () =&gt; {
                doSomething(require('./module'));
            },
            'module');"><pre class="notranslate"><code class="notranslate">        require.ensure(
            ['./module'],
            () =&gt; {
                doSomething(require('./module'));
            },
            'module');
</code></pre></div>
<p dir="auto">Webpack generates this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="	        __webpack_require__.e/* nsure */(1, function () {
	            doSomething(__webpack_require__(2));
	        });"><pre class="notranslate"><code class="notranslate">	        __webpack_require__.e/* nsure */(1, function () {
	            doSomething(__webpack_require__(2));
	        });
</code></pre></div>
<p dir="auto">You can see, the require('./module') call is now compiled into <strong>webpack_require</strong>(2) and now everything will work correctly.</p>
<p dir="auto">Other solution is that the callback will receive a function that can handle the string as an input parameter. That means:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="	        __webpack_require__.e/* nsure */(1, function (syncedRequire) {
	            doSomething(syncedRequire('./module'));
	        });"><pre class="notranslate"><code class="notranslate">	        __webpack_require__.e/* nsure */(1, function (syncedRequire) {
	            doSomething(syncedRequire('./module'));
	        });
</code></pre></div>
<p dir="auto">in this code webpack has to pass a different function than <strong>webpack_require</strong> into this callback. So the syncedRequire shouldn't be the <strong>webpack_require</strong> function. Instead of that it has to be capable to handle the string input parameter.</p>
<ul dir="auto">
<li><strong>Browser:</strong> [all]</li>
<li><strong>Language:</strong> [all]</li>
</ul>
<p dir="auto">Feel free to close this bug anyway, if it's fixed in webpack version 2, as the workaround basically just to write require inside the function and not expecting any parameter in the callback function.</p>
<p dir="auto">So workaround again:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="        require.ensure(
            ['./module'],
            () =&gt; {
                doSomething(require('./module'));
            },
            'module');"><pre class="notranslate"><code class="notranslate">        require.ensure(
            ['./module'],
            () =&gt; {
                doSomething(require('./module'));
            },
            'module');
</code></pre></div>
<p dir="auto">Once i want to develop a custom loader which can receive an <code class="notranslate">JSON</code> options in the <code class="notranslate">query</code> as following:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var urls = JSON.stringify({
    value: {
        cdnUrl: 'http://xxx.domain.com/imgs/'
    }
});

module.exports = {
    entry: {
        index: path.resolve(__dirname, 'public', 'js', 'index.js')
    },
    output: {
        path: path.resolve(__dirname, '..', '..', '..', '..', 'public', 'build', 'js'),
        filename: '[name].bundle.js',
        chunkFilename: '[id].bundle.js',
        publicPath: '/build/js/'
    },
    module: {
        loaders: [
            {
                test: /\.scss$/,
                loader: 'my-custom-loader?' + urls
            }
        ]
    }
};"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">urls</span> <span class="pl-c1">=</span> <span class="pl-c1">JSON</span><span class="pl-kos">.</span><span class="pl-en">stringify</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
    <span class="pl-c1">value</span>: <span class="pl-kos">{</span>
        <span class="pl-c1">cdnUrl</span>: <span class="pl-s">'http://xxx.domain.com/imgs/'</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-smi">module</span><span class="pl-kos">.</span><span class="pl-c1">exports</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
    <span class="pl-c1">entry</span>: <span class="pl-kos">{</span>
        <span class="pl-c1">index</span>: <span class="pl-s1">path</span><span class="pl-kos">.</span><span class="pl-en">resolve</span><span class="pl-kos">(</span><span class="pl-s1">__dirname</span><span class="pl-kos">,</span> <span class="pl-s">'public'</span><span class="pl-kos">,</span> <span class="pl-s">'js'</span><span class="pl-kos">,</span> <span class="pl-s">'index.js'</span><span class="pl-kos">)</span>
    <span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-c1">output</span>: <span class="pl-kos">{</span>
        <span class="pl-c1">path</span>: <span class="pl-s1">path</span><span class="pl-kos">.</span><span class="pl-en">resolve</span><span class="pl-kos">(</span><span class="pl-s1">__dirname</span><span class="pl-kos">,</span> <span class="pl-s">'..'</span><span class="pl-kos">,</span> <span class="pl-s">'..'</span><span class="pl-kos">,</span> <span class="pl-s">'..'</span><span class="pl-kos">,</span> <span class="pl-s">'..'</span><span class="pl-kos">,</span> <span class="pl-s">'public'</span><span class="pl-kos">,</span> <span class="pl-s">'build'</span><span class="pl-kos">,</span> <span class="pl-s">'js'</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
        <span class="pl-c1">filename</span>: <span class="pl-s">'[name].bundle.js'</span><span class="pl-kos">,</span>
        <span class="pl-c1">chunkFilename</span>: <span class="pl-s">'[id].bundle.js'</span><span class="pl-kos">,</span>
        <span class="pl-c1">publicPath</span>: <span class="pl-s">'/build/js/'</span>
    <span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-c1">module</span>: <span class="pl-kos">{</span>
        <span class="pl-c1">loaders</span>: <span class="pl-kos">[</span>
            <span class="pl-kos">{</span>
                <span class="pl-c1">test</span>: <span class="pl-pds"><span class="pl-c1">/</span><span class="pl-cce">\.</span>scss<span class="pl-cce">$</span><span class="pl-c1">/</span></span><span class="pl-kos">,</span>
                <span class="pl-c1">loader</span>: <span class="pl-s">'my-custom-loader?'</span> <span class="pl-c1">+</span> <span class="pl-s1">urls</span>
            <span class="pl-kos">}</span>
        <span class="pl-kos">]</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">The thing i found is the <code class="notranslate">this.query</code> always remove one <code class="notranslate">/</code> right after <code class="notranslate">http:</code> from the passed options:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="module.exports = function(source) {
    'use strict';
    this.cacheable &amp;&amp; this.cacheable();
    console.log(this.query);//?{&quot;value&quot;:{&quot;cdnUrl&quot;:&quot;http:/xxx.domain.com/imgs/&quot;}}
};"><pre class="notranslate"><span class="pl-smi">module</span><span class="pl-kos">.</span><span class="pl-en">exports</span> <span class="pl-c1">=</span> <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-s1">source</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-s">'use strict'</span><span class="pl-kos">;</span>
    <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">cacheable</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-en">cacheable</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">query</span><span class="pl-kos">)</span><span class="pl-kos">;</span><span class="pl-c">//?{"value":{"cdnUrl":"http:/xxx.domain.com/imgs/"}}</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Is this by design?</p>