javascriptwebpackbabeljsbabel-preset-env

@babel/preset-env not reading browserslist from package.config


I have created the environment variable (user and system) BROWSERSLIST_CONFIG and set it to C:\Program Files (x86)\Microsoft VS Code\bin\package.json.

However, when I run webpack and set debug to true I get empty targets:

@babel/preset-env: `DEBUG` option

Using targets:
{}

Even though my package.json has the following:

"browserslist":{
    "DEBUG": ["last 2 Firefox versions"],
    "PRODUCTION": ["> 2%", "last 2 versions", "ie >= 11"]
},

If I add the targets/browsers option directly into webpack.config it works fine but I have multiple projects and I want to share a central package.config.

Is there something missing in how I call babel-loader?

{
    test: /\.js$/,
    exclude: /node_modules/,
    use: {
        loader: 'babel-loader',
        options: {
            presets: [[nodeFolder + '@babel/preset-env', {
                targets: {
                  browsers: [
                    "last 2 Chrome versions"
                  ]
                }, "debug": true
              },
            ]],
        },
    },
},

Solution

  • Fixed. I added in the path to the config's directory as an option to the preset:

    use: {
        loader: 'babel-loader',
        options: {
            presets: [[nodeFolder + '@babel/preset-env', { 
                "debug": true,
                 "configPath": 'C:\\Program Files (x86)\\Microsoft VS Code\\bin\\'
              },
            ]],
        },
    },