Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webpack --migrate error #83

Closed
taylorRohrer opened this issue Mar 7, 2017 · 0 comments · Fixed by #91
Closed

webpack --migrate error #83

taylorRohrer opened this issue Mar 7, 2017 · 0 comments · Fixed by #91

Comments

@taylorRohrer
Copy link

Do you want to request a feature or report a bug?
Bug v1=>v2

Command Ran
set NODE_ENV 'development' && node ../webpack-cli/bin/webpack.js --migrate webpack.config.js

v1 config

var webpack = require('webpack');
var nodeEnvironment = process.env.NODE_ENV
var _ = require('lodash');

var config = {
  entry: {
    'lib': './app/index.js',
    'email': './app/email.js'
  },
  plugins: [
    new webpack.DefinePlugin({
      'INCLUDE_ALL_MODULES': function includeAllModulesGlobalFn(modulesArray, application) {
        modulesArray.forEach(function executeModuleIncludesFn(moduleFn) {
          moduleFn(application);
        });
      },
      ENVIRONMENT: JSON.stringify(nodeEnvironment)
    })
  ],
  output: {
    path: __dirname + '/app',
    filename: 'bundle.js'
  },
  resolve: {
    root: __dirname + '/app'
  },
  module: {
    // preLoaders: [
    //   { test: /\.js?$/, loader: 'eslint', exclude: /node_modules/ }
    // ],
    loaders: [
      { test: /\.js$/, exclude: /(node_modules)/, loader: 'babel' },
      { test: /\.html/, exclude: [/(node_modules)/, /src\/index\.html/], loader: 'html-loader' },
      { test: /\.s?css$/, loader: 'style!css!sass' },
      { test: /\.(png|jpg)$/, loader: 'url-loader?mimetype=image/png' }
    ]
  },
  // extra configuration options. 
  // eslint: {
  //   configFile: '.eslintrc.js'
  // }
}

switch (nodeEnvironment) {
  case 'production':
    config.plugins.push(new webpack.optimize.UglifyJsPlugin());
    case 'preproduction':
      config.output.path = __dirname + '/dist';
      config.plugins.push(new webpack.optimize.DedupePlugin());
      config.plugins.push(new webpack.optimize.OccurenceOrderPlugin());

      config.output.filename = '[name].js';

      config.entry = {
        'lib': ['./app/index.js', 'angular', 'lodash'],
        'email': ['./app/email.js', 'angular']
      };

      config.devtool = 'source-map';
      config.output.libraryTarget = 'commonjs2';
    
    break;

  case 'test':
    config.entry = './index.js';
    break;

  case 'development':
    config.entry = {
      'lib': ['./app/index.js', 'webpack/hot/dev-server'],
      'email': ['./app/email.js', 'webpack/hot/dev-server']
    };
    config.output.filename = '[name].js';
    config.devtool = 'source-map';
    break;

  default:
    console.warn('Unknown or Undefined Node Environment. Please refer to package.json for available build commands.');
}

module.exports = config;

Output

/mutualofomaha.com/workbench/mutualofomaha/webpack-cli/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.js:15
                        if (path.parent.value.elements.length === 1) {
                                                      ^

TypeError: Cannot read property 'length' of undefined
    at NodePath.findPluginsByName.forEach.path (/mutualofomaha.com/workbench/mutualofomaha/webpack-cli/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.js:15:34)
    at __paths.forEach (/mutualofomaha.com/workbench/mutualofomaha/webpack-cli/node_modules/jscodeshift/dist/Collection.js:76:36)
    at Array.forEach (native)
    at Collection.forEach (/mutualofomaha.com/workbench/mutualofomaha/webpack-cli/node_modules/jscodeshift/dist/Collection.js:75:18)
    at module.exports (/mutualofomaha.com/workbench/mutualofomaha/webpack-cli/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.js:12:4)
    at transforms.forEach.f (/mutualofomaha.com/workbench/mutualofomaha/webpack-cli/lib/transformations/index.js:40:26)
    at Array.forEach (native)
    at transform (/mutualofomaha.com/workbench/mutualofomaha/webpack-cli/lib/transformations/index.js:40:13)
    at module.exports (/mutualofomaha.com/workbench/mutualofomaha/webpack-cli/lib/migrate.js:9:23)
    at Object.<anonymous> (/mutualofomaha.com/workbench/mutualofomaha/webpack-cli/bin/webpack.js:171:30)
okonet added a commit that referenced this issue Mar 19, 2017
For now only plugins instantiated in an array can be removed since this is safe.
All other usages are considered not safe and thus won't be modified.

- Display a message about the current support

Closes #83
pksjce pushed a commit that referenced this issue Mar 21, 2017
* fix: Guard new exepressions outside of arrays

For now only plugins instantiated in an array can be removed since this is safe.
All other usages are considered not safe and thus won't be modified.

- Display a message about the current support

Closes #83

* style: Better error messages

- Pass the source to the transform function
- This allows displaying code snippets in error messages

* fix: Use console.log to fix colors and use better error copy.

- Don't use `console.error` to fix colors.
- Use chalk instead to make output more prettier.
- Better error message with an example of the expected usage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants