trayio / babel-plugin-webpack-alias

babel 6 plugin which allows to use webpack resolve options
MIT License
150 stars 32 forks source link

Resolved config doesn't contain a resolve configuration #24

Open benduran opened 8 years ago

benduran commented 8 years ago

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 commented 8 years ago

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

piersadrian commented 8 years ago

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

benduran commented 8 years ago

@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.

adriantoine commented 8 years ago

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 commented 8 years ago

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

adriantoine commented 8 years ago

@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 commented 8 years ago

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.

vladinator1000 commented 8 years ago

+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.

benduran commented 8 years ago

@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

adriantoine commented 8 years ago

@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.

McChen commented 8 years ago

+1

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

adriantoine commented 8 years ago

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?

vladinator1000 commented 8 years ago

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

McChen commented 8 years ago

@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.

pawelrychlik commented 8 years ago

yep, 1.8.2 works like a charm.

kwelch commented 8 years ago

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

pawelrychlik commented 8 years ago

@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 ~.