<p dir="auto">I have been trying to figure this out for over an hour now. Here is the subject code:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const ENVIRONMENT = process.env.NODE_ENV;
const BASENAME = process.env.APP_BASENAME;

console.log('process.env', {
    ENVIRONMENT: ENVIRONMENT,
    'process.env': process.env,
    NODE_ENV: process.env.NODE_ENV,
    APP_BASENAME: process.env.APP_BASENAME
});

if (ENVIRONMENT !== 'development' &amp;&amp; ENVIRONMENT !== 'production') {
    throw new Error('Unknown ENVIRONMENT.');
}

export {
    BASENAME,
    ENVIRONMENT
};
"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-c1">ENVIRONMENT</span> <span class="pl-c1">=</span> <span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">env</span><span class="pl-kos">.</span><span class="pl-c1">NODE_ENV</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-c1">BASENAME</span> <span class="pl-c1">=</span> <span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">env</span><span class="pl-kos">.</span><span class="pl-c1">APP_BASENAME</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-s">'process.env'</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
    <span class="pl-c1">ENVIRONMENT</span>: <span class="pl-c1">ENVIRONMENT</span><span class="pl-kos">,</span>
    <span class="pl-s">'process.env'</span>: <span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">env</span><span class="pl-kos">,</span>
    <span class="pl-c1">NODE_ENV</span>: <span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">env</span><span class="pl-kos">.</span><span class="pl-c1">NODE_ENV</span><span class="pl-kos">,</span>
    <span class="pl-c1">APP_BASENAME</span>: <span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">env</span><span class="pl-kos">.</span><span class="pl-c1">APP_BASENAME</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-c1">ENVIRONMENT</span> <span class="pl-c1">!==</span> <span class="pl-s">'development'</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-c1">ENVIRONMENT</span> <span class="pl-c1">!==</span> <span class="pl-s">'production'</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">throw</span> <span class="pl-k">new</span> <span class="pl-v">Error</span><span class="pl-kos">(</span><span class="pl-s">'Unknown ENVIRONMENT.'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">export</span> <span class="pl-kos">{</span>
    <span class="pl-c1">BASENAME</span><span class="pl-kos">,</span>
    <span class="pl-c1">ENVIRONMENT</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Here is my webpack config:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const webpack = require('webpack');
const path = require('path');

module.exports = {
    devtool: 'source-map',
    debug: false,
    context: __dirname,
    entry: {
        'app': [
            path.resolve(__dirname, './src/app')
        ]
    },
    output: {
        path: path.resolve(__dirname, './dist'),
        filename: '[name].js',
        publicPath: '/static/'
    },
    plugins: [
        new webpack.optimize.UglifyJsPlugin({
            compressor: {
                /* eslint-disable camelcase */
                screw_ie8: true,
                /* eslint-enable */
                warnings: false
            }
        }),
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': '&quot;production&quot;',
            'process.env.APP_BASENAME': '&quot;' + (process.env.APP_BASENAME || '') + '&quot;'
        }),
        new webpack.DefinePlugin({
            'process.env': {
                NODE_ENV: '&quot;production&quot;',
                APP_BASENAME: '&quot;' + (process.env.APP_BASENAME || '') + '&quot;'
            }
        }),
        new webpack.optimize.OccurrenceOrderPlugin(),
        new webpack.optimize.DedupePlugin(),
        new webpack.NoErrorsPlugin()
    ],
    module: {
        loaders: [
            {
                include: path.resolve(__dirname, './src'),
                loader: 'babel',
                test: /\.js$/,
            },
            {
                loaders: [
                    'style?sourceMap',
                    'css?modules&amp;importLoaders=1&amp;localIdentName=[name]___[local]___[hash:base64:5]',
                    'resolve-url',
                    'sass?sourceMap'
                ],
                test: /\.scss$/
            }
        ]
    }
};
"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">webpack</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'webpack'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">path</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'path'</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">devtool</span>: <span class="pl-s">'source-map'</span><span class="pl-kos">,</span>
    <span class="pl-c1">debug</span>: <span class="pl-c1">false</span><span class="pl-kos">,</span>
    <span class="pl-c1">context</span>: <span class="pl-s1">__dirname</span><span class="pl-kos">,</span>
    <span class="pl-c1">entry</span>: <span class="pl-kos">{</span>
        <span class="pl-s">'app'</span>: <span class="pl-kos">[</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">'./src/app'</span><span class="pl-kos">)</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">'./dist'</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
        <span class="pl-c1">filename</span>: <span class="pl-s">'[name].js'</span><span class="pl-kos">,</span>
        <span class="pl-c1">publicPath</span>: <span class="pl-s">'/static/'</span>
    <span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-c1">plugins</span>: <span class="pl-kos">[</span>
        <span class="pl-k">new</span> <span class="pl-s1">webpack</span><span class="pl-kos">.</span><span class="pl-c1">optimize</span><span class="pl-kos">.</span><span class="pl-c1">UglifyJsPlugin</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
            <span class="pl-c1">compressor</span>: <span class="pl-kos">{</span>
                <span class="pl-c">/* eslint-disable camelcase */</span>
                <span class="pl-c1">screw_ie8</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
                <span class="pl-c">/* eslint-enable */</span>
                <span class="pl-c1">warnings</span>: <span class="pl-c1">false</span>
            <span class="pl-kos">}</span>
        <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
        <span class="pl-k">new</span> <span class="pl-s1">webpack</span><span class="pl-kos">.</span><span class="pl-c1">DefinePlugin</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
            <span class="pl-s">'process.env.NODE_ENV'</span>: <span class="pl-s">'"production"'</span><span class="pl-kos">,</span>
            <span class="pl-s">'process.env.APP_BASENAME'</span>: <span class="pl-s">'"'</span> <span class="pl-c1">+</span> <span class="pl-kos">(</span><span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">env</span><span class="pl-kos">.</span><span class="pl-c1">APP_BASENAME</span> <span class="pl-c1">||</span> <span class="pl-s">''</span><span class="pl-kos">)</span> <span class="pl-c1">+</span> <span class="pl-s">'"'</span>
        <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
        <span class="pl-k">new</span> <span class="pl-s1">webpack</span><span class="pl-kos">.</span><span class="pl-c1">DefinePlugin</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
            <span class="pl-s">'process.env'</span>: <span class="pl-kos">{</span>
                <span class="pl-c1">NODE_ENV</span>: <span class="pl-s">'"production"'</span><span class="pl-kos">,</span>
                <span class="pl-c1">APP_BASENAME</span>: <span class="pl-s">'"'</span> <span class="pl-c1">+</span> <span class="pl-kos">(</span><span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">env</span><span class="pl-kos">.</span><span class="pl-c1">APP_BASENAME</span> <span class="pl-c1">||</span> <span class="pl-s">''</span><span class="pl-kos">)</span> <span class="pl-c1">+</span> <span class="pl-s">'"'</span>
            <span class="pl-kos">}</span>
        <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
        <span class="pl-k">new</span> <span class="pl-s1">webpack</span><span class="pl-kos">.</span><span class="pl-c1">optimize</span><span class="pl-kos">.</span><span class="pl-c1">OccurrenceOrderPlugin</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
        <span class="pl-k">new</span> <span class="pl-s1">webpack</span><span class="pl-kos">.</span><span class="pl-c1">optimize</span><span class="pl-kos">.</span><span class="pl-c1">DedupePlugin</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
        <span class="pl-k">new</span> <span class="pl-s1">webpack</span><span class="pl-kos">.</span><span class="pl-c1">NoErrorsPlugin</span><span class="pl-kos">(</span><span class="pl-kos">)</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">include</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">'./src'</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
                <span class="pl-c1">loader</span>: <span class="pl-s">'babel'</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>js<span class="pl-cce">$</span><span class="pl-c1">/</span></span><span class="pl-kos">,</span>
            <span class="pl-kos">}</span><span class="pl-kos">,</span>
            <span class="pl-kos">{</span>
                <span class="pl-c1">loaders</span>: <span class="pl-kos">[</span>
                    <span class="pl-s">'style?sourceMap'</span><span class="pl-kos">,</span>
                    <span class="pl-s">'css?modules&amp;importLoaders=1&amp;localIdentName=[name]___[local]___[hash:base64:5]'</span><span class="pl-kos">,</span>
                    <span class="pl-s">'resolve-url'</span><span class="pl-kos">,</span>
                    <span class="pl-s">'sass?sourceMap'</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-kos">]</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">As you can see, I have tried multiple methods of using <code class="notranslate">DefinePlugin</code>:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="new webpack.DefinePlugin({
    'process.env.NODE_ENV': '&quot;production&quot;',
    'process.env.APP_BASENAME': '&quot;' + (process.env.APP_BASENAME || '') + '&quot;'
}),
new webpack.DefinePlugin({
    'process.env': {
        NODE_ENV: '&quot;production&quot;',
        APP_BASENAME: '&quot;' + (process.env.APP_BASENAME || '') + '&quot;'
    }
}),"><pre class="notranslate"><span class="pl-k">new</span> <span class="pl-s1">webpack</span><span class="pl-kos">.</span><span class="pl-c1">DefinePlugin</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
    <span class="pl-s">'process.env.NODE_ENV'</span>: <span class="pl-s">'"production"'</span><span class="pl-kos">,</span>
    <span class="pl-s">'process.env.APP_BASENAME'</span>: <span class="pl-s">'"'</span> <span class="pl-c1">+</span> <span class="pl-kos">(</span><span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">env</span><span class="pl-kos">.</span><span class="pl-c1">APP_BASENAME</span> <span class="pl-c1">||</span> <span class="pl-s">''</span><span class="pl-kos">)</span> <span class="pl-c1">+</span> <span class="pl-s">'"'</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
<span class="pl-k">new</span> <span class="pl-s1">webpack</span><span class="pl-kos">.</span><span class="pl-c1">DefinePlugin</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
    <span class="pl-s">'process.env'</span>: <span class="pl-kos">{</span>
        <span class="pl-c1">NODE_ENV</span>: <span class="pl-s">'"production"'</span><span class="pl-kos">,</span>
        <span class="pl-c1">APP_BASENAME</span>: <span class="pl-s">'"'</span> <span class="pl-c1">+</span> <span class="pl-kos">(</span><span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">env</span><span class="pl-kos">.</span><span class="pl-c1">APP_BASENAME</span> <span class="pl-c1">||</span> <span class="pl-s">''</span><span class="pl-kos">)</span> <span class="pl-c1">+</span> <span class="pl-s">'"'</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">Here is the console output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
    APP_BASENAME: &quot;/campaign-master/upload-static&quot;,
    ENVIRONMENT: undefined,
    NODE_ENV: undefined,
    process.env: {
        APP_BASENAME: &quot;/campaign-master/upload-static&quot;,
        NODE_ENV: &quot;production&quot;
    }
}"><pre class="notranslate"><code class="notranslate">{
    APP_BASENAME: "/campaign-master/upload-static",
    ENVIRONMENT: undefined,
    NODE_ENV: undefined,
    process.env: {
        APP_BASENAME: "/campaign-master/upload-static",
        NODE_ENV: "production"
    }
}
</code></pre></div>
<p dir="auto">The script execution ends with an exception:</p>
<blockquote>
<p dir="auto">Uncaught Error: Unknown ENVIRONMENT.</p>
</blockquote>
<p dir="auto">As a result of the condition that you can see in the <code class="notranslate">config.js</code>.</p>
<p dir="auto">What is the reason <code class="notranslate">process.env.NODE_ENV</code> is not getting replaced?</p>
<h2 dir="auto">Feature request</h2>
<p dir="auto"><strong>What is the expected behavior?</strong></p>
<p dir="auto">Various parts of Webpack's (semi-)internal runtime depend on a native <code class="notranslate">Promise</code> being available.<br>
Currently, browsers which do not have a native implementation require that it be polyfilled globally.</p>
<p dir="auto">It would be nice if Webpack would provide a way to hook in a <em>local</em> polyfill instead; one which does not require writing to <code class="notranslate">window</code>.</p>
<p dir="auto"><strong>What is motivation or use case for adding/changing the behavior?</strong></p>
<p dir="auto">Projects that act as third-parties inside the websites of others generally need to minimize the way in which they affect the global environment. Currently it is impossible to avoid injecting a global polyfill for <code class="notranslate">Promise</code> when you really on key functionalities like ES6 dynamic <code class="notranslate">import()</code>.</p>
<p dir="auto"><strong>How should this be implemented in your opinion?</strong></p>
<ol dir="auto">
<li>Centralize creation of <code class="notranslate">Promise</code> instances by code generators. (Seems a lot of it is already being done through <code class="notranslate">RuntimeTemplate</code>'s <code class="notranslate">blockPromise</code>, actually.)</li>
<li>Add a configuration property that can be set to a user-space module to be pulled in, instead of accessing the global <code class="notranslate">Promise</code>.</li>
</ol>
<p dir="auto"><strong>Are you willing to work on this yourself?</strong></p>
<p dir="auto">Willing; yes. Able; no.<br>
Simply don't have the time.</p>