babel-plugin-webpack-alias icon indicating copy to clipboard operation
babel-plugin-webpack-alias copied to clipboard

Resolved config doesn't contain a resolve configuration

Open benduran opened this issue 7 years ago • 17 comments

I've seen this issue in a closed github issue, but I just installed v2.0.0 of this plugin and received the same issue. Here are my configs for reference:

Webpack.config

const config = Object.assign({
    entry: entryPoint,
    output: {
        filename: outputFileName,
        library: libraryName,
        libraryTarget: 'umd',
        umdNamedDefine: true
    },
    module: {
        loaders: [{
            test: /\.(jsx|js)$/,
            exclude: /(node_modules)/,
            loader: 'babel',
            query: {
                presets: ['es2015', 'react'],
                plugins: ['transform-object-rest-spread', 'transform-class-properties']
            }
        }, {
            test: /\.(styl|css)$/,
            loader: 'style-loader!css-loader!postcss-loader!stylus-loader'
        }, {
            test: /\.(woff2|woff|eot|ttf|svg|otf|png|jpg|jpeg)$/,
            exclude: /(node_modules)/,
            loader: 'url-loader'
        }]
    },
    postcss: function () {
        return [require('autoprefixer')({
            browsers: [
                'last 2 versions'
            ]
        })];
    },
    resolve: {
        alias: {
            'jquery-ui': 'jquery-ui/ui/widgets',
            'sharedScript': path.resolve('./shared/script')
        },
        extensions: ['', '.jsx', '.js', '.styl']
    },
    plugins: [new webpack.DefinePlugin({
        'process.env': {
            NODE_ENV: '"development"',
            UNITY_ENV: '"production"', // If you're building a DEV build from the Unity interface, change this to "development",
            BUILD_VERSION: '"' + readVersionNumber(args) + '"',
            JAVASCRIPT_INTERFACE_NAME: '"' + (buildForRP ? 'ProspectorJavascriptInterface' : 'OnsightJavascriptInterface') + '"',
            LIBRARY_NAME: '"' + libraryName + '"'
        }
    })]
}, production ? {
    plugins: [new webpack.optimize.UglifyJsPlugin({
        compress: {
            sequences: true,
            booleans: true,
            warnings: false,
            drop_debugger: true,
            drop_console: true
        },
        mangle: {
            except: ['$']
        },
        comments: false
    }), new webpack.DefinePlugin({
        'process.env': {
            NODE_ENV: '"production"',
            UNITY_ENV: '"production"', // If you're building a DEV build from the Unity interface, change this to "development",
            BUILD_VERSION: '"' + readVersionNumber(args) + '"',
            JAVASCRIPT_INTERFACE_NAME: '"' + (buildForRP ? 'ProspectorJavascriptInterface' : 'OnsightJavascriptInterface') + '"',
            LIBRARY_NAME: '"' + libraryName + '"'
        }
    })]
} : {});

module.exports = config;
package.json babel config
"babel": {
    "presets": [
      "es2015",
      "react"
    ],
    "plugins": [
      "transform-object-rest-spread",
      "transform-class-properties",
      ["babel-plugin-webpack-alias", { "config": "./webpack.config.js", "findConfig": true }]
    ]
  }

Error, for reference

throw err;
        ^

Error: D:/web/webpack.config.js: The resolved config file doesn't contain a resolve configuration

benduran avatar Sep 07 '16 18:09 benduran

And go figure, as soon as I post this, I figure out the problem.

benduran avatar Sep 07 '16 18:09 benduran

@benduran what was the issue? Having the same problem here.

piersadrian avatar Sep 07 '16 22:09 piersadrian

@piersadrian For me, it's a problem that is harder to correct. My build is heavily reliant on CLI arguments, which is something mocha doesn't handle out of the box (meaning pass-through). My webpack.config wasn't being transformed correctly because of this.

benduran avatar Sep 07 '16 22:09 benduran

Hi! If this is a problem, use v1.9.0 until I fix that. I released this one as a major release so that npm doesn't auto install this version for people having "^1.9.0" in their package.json.

I'll look into that as soon as I can.

adriantoine avatar Sep 08 '16 07:09 adriantoine

I can't really reproduce that, @piersadrian can you give me more info about your dev environment and configuration? Thanks!

adriantoine avatar Sep 08 '16 09:09 adriantoine

@piersadrian are you using v2.0.0? This issue was occurring with v1.8.3 but I thought I fixed it in v2.0.0.

adriantoine avatar Sep 08 '16 09:09 adriantoine

I can't replicate the issue at the moment and I can't investigate without more information, so I will close that for now, feel free to comment if you can provide more info.

adriantoine avatar Sep 12 '16 12:09 adriantoine

+1 having the same issue, .babelrc:

{
  "presets": ["react", "es2015", "stage-1", "stage-0"],
  "plugins": [
    "react-hot-loader/babel",
    [
        "babel-plugin-webpack-alias",
        {
            "config": "webpack.config.dev.js",
            "findConfig": true
        }
    ]
  ]
}

webpack.config.dev.js:

const path = require('path');
const webpack = require('webpack');

module.exports = {
    // ...
    resolve: {
        modulesDirectories: ['node_modules', 'client', 'components', 'stores'],
        extensions: ['', '.js', '.scss', 'svg', 'ttf', 'woff', 'eot'],
        root: [path.join(__dirname, './client')],

        alias: {
            assets: path.resolve(__dirname, './client/assets'),
            stylesheets: path.resolve(__dirname, './client/stylesheets'),
            client: path.resolve(__dirname, './client'),
            components: path.resolve(__dirname, './client/components'),
            actions: path.resolve(__dirname, './client/actions'),
            reducers: path.resolve(__dirname, './client/reducers'),
        },
    },
};

EDIT: To anyone having this problem: try using path.join() instead of path.resolve(). I think that's what causing it.

vladinator1000 avatar Oct 07 '16 02:10 vladinator1000

@savovs Thanks for pointing this out. I ended up running into this issue again yesterday when setting up a new test project. Rolling back to 1.8.2 fixed the issue for me, though that version is quite old now.

I'll upgrade back to the current version and try swapping over to path.join and report my findings

benduran avatar Oct 07 '16 15:10 benduran

@benduran @savovs don't worry about using v1.8.2, the library hasn't changed much since then. I'll have a look at that as soon as I can.

adriantoine avatar Oct 07 '16 15:10 adriantoine

+1

Having the same issue, with similar configuration, on version 2.1.1. Rolling back to 2.1.0 works for me.

McChen avatar Oct 12 '16 01:10 McChen

Thanks for the feedback, at the moment the only way to fix this seems to rollback to 1.8.2.

I don't have time to work on this for now. Can anyone make a small repo which replicates this issue?

adriantoine avatar Oct 12 '16 08:10 adriantoine

@McChen have you tried changing path.resolve()s to path.join()s in your webpack config? That fixed the issue for me.

vladinator1000 avatar Oct 12 '16 13:10 vladinator1000

@savovs I was using path.join() to begin with actually. 2.1.0 but had to rollback all the way to 1.8.2 on Jenkins.

McChen avatar Oct 12 '16 22:10 McChen

yep, 1.8.2 works like a charm.

pawelrychlik avatar Oct 21 '16 15:10 pawelrychlik

@pawelrychlik I am trying this with 1.8.2 but it is not working are you using path.join or path.resolve

kwelch avatar Oct 21 '16 16:10 kwelch

@kwelch path.join does the job for me. A snippet from my webpack config:

    alias: {
      'config': path.join(__dirname, './config/index.js'),
    },

And I'm explicitly using exactly "1.8.2" in package.js, with no ^ or ~.

pawelrychlik avatar Oct 21 '16 20:10 pawelrychlik