{"action":"created","issue":{"url":"https://api.github.com/repos/webpack/webpack/issues/2427","repository_url":"https://api.github.com/repos/webpack/webpack","labels_url":"https://api.github.com/repos/webpack/webpack/issues/2427/labels{/name}","comments_url":"https://api.github.com/repos/webpack/webpack/issues/2427/comments","events_url":"https://api.github.com/repos/webpack/webpack/issues/2427/events","html_url":"https://github.com/webpack/webpack/issues/2427","id":152529417,"number":2427,"title":"DefinePlugin does not inject variable","user":{"login":"gajus","id":973543,"avatar_url":"https://avatars.githubusercontent.com/u/973543?v=3","gravatar_id":"","url":"https://api.github.com/users/gajus","html_url":"https://github.com/gajus","followers_url":"https://api.github.com/users/gajus/followers","following_url":"https://api.github.com/users/gajus/following{/other_user}","gists_url":"https://api.github.com/users/gajus/gists{/gist_id}","starred_url":"https://api.github.com/users/gajus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gajus/subscriptions","organizations_url":"https://api.github.com/users/gajus/orgs","repos_url":"https://api.github.com/users/gajus/repos","events_url":"https://api.github.com/users/gajus/events{/privacy}","received_events_url":"https://api.github.com/users/gajus/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-05-02T10:39:30Z","updated_at":"2016-05-02T10:55:00Z","closed_at":"2016-05-02T10:55:00Z","body":"I have been trying to figure this out for over an hour now. Here is the subject code:\r\n\r\n```js\r\nconst ENVIRONMENT = process.env.NODE_ENV;\r\nconst BASENAME = process.env.APP_BASENAME;\r\n\r\nconsole.log('process.env', {\r\n    ENVIRONMENT: ENVIRONMENT,\r\n    'process.env': process.env,\r\n    NODE_ENV: process.env.NODE_ENV,\r\n    APP_BASENAME: process.env.APP_BASENAME\r\n});\r\n\r\nif (ENVIRONMENT !== 'development' && ENVIRONMENT !== 'production') {\r\n    throw new Error('Unknown ENVIRONMENT.');\r\n}\r\n\r\nexport {\r\n    BASENAME,\r\n    ENVIRONMENT\r\n};\r\n\r\n```\r\n\r\nHere is my webpack config:\r\n\r\n```js\r\nconst webpack = require('webpack');\r\nconst path = require('path');\r\n\r\nmodule.exports = {\r\n    devtool: 'source-map',\r\n    debug: false,\r\n    context: __dirname,\r\n    entry: {\r\n        'app': [\r\n            path.resolve(__dirname, './src/app')\r\n        ]\r\n    },\r\n    output: {\r\n        path: path.resolve(__dirname, './dist'),\r\n        filename: '[name].js',\r\n        publicPath: '/static/'\r\n    },\r\n    plugins: [\r\n        new webpack.optimize.UglifyJsPlugin({\r\n            compressor: {\r\n                /* eslint-disable camelcase */\r\n                screw_ie8: true,\r\n                /* eslint-enable */\r\n                warnings: false\r\n            }\r\n        }),\r\n        new webpack.DefinePlugin({\r\n            'process.env.NODE_ENV': '\"production\"',\r\n            'process.env.APP_BASENAME': '\"' + (process.env.APP_BASENAME || '') + '\"'\r\n        }),\r\n        new webpack.DefinePlugin({\r\n            'process.env': {\r\n                NODE_ENV: '\"production\"',\r\n                APP_BASENAME: '\"' + (process.env.APP_BASENAME || '') + '\"'\r\n            }\r\n        }),\r\n        new webpack.optimize.OccurrenceOrderPlugin(),\r\n        new webpack.optimize.DedupePlugin(),\r\n        new webpack.NoErrorsPlugin()\r\n    ],\r\n    module: {\r\n        loaders: [\r\n            {\r\n                include: path.resolve(__dirname, './src'),\r\n                loader: 'babel',\r\n                test: /\\.js$/,\r\n            },\r\n            {\r\n                loaders: [\r\n                    'style?sourceMap',\r\n                    'css?modules&importLoaders=1&localIdentName=[name]___[local]___[hash:base64:5]',\r\n                    'resolve-url',\r\n                    'sass?sourceMap'\r\n                ],\r\n                test: /\\.scss$/\r\n            }\r\n        ]\r\n    }\r\n};\r\n\r\n```\r\n\r\nAs you can see, I have tried multiple methods of using `DefinePlugin`:\r\n\r\n```js\r\nnew webpack.DefinePlugin({\r\n    'process.env.NODE_ENV': '\"production\"',\r\n    'process.env.APP_BASENAME': '\"' + (process.env.APP_BASENAME || '') + '\"'\r\n}),\r\nnew webpack.DefinePlugin({\r\n    'process.env': {\r\n        NODE_ENV: '\"production\"',\r\n        APP_BASENAME: '\"' + (process.env.APP_BASENAME || '') + '\"'\r\n    }\r\n}),\r\n```\r\n\r\nHere is the console output:\r\n\r\n```\r\n{\r\n    APP_BASENAME: \"/campaign-master/upload-static\",\r\n    ENVIRONMENT: undefined,\r\n    NODE_ENV: undefined,\r\n    process.env: {\r\n        APP_BASENAME: \"/campaign-master/upload-static\",\r\n        NODE_ENV: \"production\"\r\n    }\r\n}\r\n```\r\n\r\nThe script execution ends with an exception:\r\n\r\n> Uncaught Error: Unknown ENVIRONMENT.\r\n\r\nAs a result of the condition that you can see in the `config.js`.\r\n\r\nWhat is the reason `process.env.NODE_ENV` is not getting replaced?"},"comment":{"url":"https://api.github.com/repos/webpack/webpack/issues/comments/216198326","html_url":"https://github.com/webpack/webpack/issues/2427#issuecomment-216198326","issue_url":"https://api.github.com/repos/webpack/webpack/issues/2427","id":216198326,"user":{"login":"gajus","id":973543,"avatar_url":"https://avatars.githubusercontent.com/u/973543?v=3","gravatar_id":"","url":"https://api.github.com/users/gajus","html_url":"https://github.com/gajus","followers_url":"https://api.github.com/users/gajus/followers","following_url":"https://api.github.com/users/gajus/following{/other_user}","gists_url":"https://api.github.com/users/gajus/gists{/gist_id}","starred_url":"https://api.github.com/users/gajus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gajus/subscriptions","organizations_url":"https://api.github.com/users/gajus/orgs","repos_url":"https://api.github.com/users/gajus/repos","events_url":"https://api.github.com/users/gajus/events{/privacy}","received_events_url":"https://api.github.com/users/gajus/received_events","type":"User","site_admin":false},"created_at":"2016-05-02T10:55:00Z","updated_at":"2016-05-02T10:55:00Z","body":"That was painful experience.\r\n\r\nMy `.babelrc` has been configured as:\r\n\r\n```json\r\n{\r\n    \"presets\": [\r\n        \"es2015\",\r\n        \"stage-0\",\r\n        \"react\"\r\n    ],\r\n    \"plugins\": [\r\n        \"transform-export-default-name\",\r\n        \"lodash-modularize\",\r\n        \"transform-node-env-inline\"\r\n    ],\r\n    \"env\": {\r\n        \"development\": {\r\n            \"presets\": [\r\n                \"react-hmre\"\r\n            ],\r\n            \"plugins\": [\r\n                \"typecheck\"\r\n            ]\r\n        }\r\n    }\r\n}\r\n\r\n```\r\n\r\nwhile I was executing webpack using:\r\n\r\n```js\r\nAPP_BASENAME='/campaign-master/upload-static' webpack --config ./webpack.config.production.js\r\n```\r\n\r\ni.e. `babel-preset-react-hmre` is breaking `DefinePlugin`."}}