1

After updating project dependencies I started seeing this error, there appears to be a versioning problem with the object-assign Babel 5 plugin.

After the update I use Babel 6, the closest plugin I could find is es6-object-assign, but the use of it results in error (error shown below).

Use of browserify + babelify + object-assign in my app:

var babelify = require('babelify');
var browserify = require('browserify-middleware');
var keystone = require('keystone');

var importRoutes = keystone.importer(__dirname);

// Setup Route Bindings
exports = module.exports = function(app) {
    app.use('/js', browserify('./client/scripts', {
        transform: [babelify.configure({
            plugins: ['object-assign']
        })]
    }));
    // Views
    app.use(function(req, res) {
        res.render('index');
    });
};

Server log:

GET / 304 260.457 ms
Error thrown for request: /js/Application.js
Error: The (object-assign) Babel 5 plugin is being run with Babel 6. while parsing file: /home/user/project/client/scripts/Application.js
    at new Plugin (/home/user/project/node_modules/babel-core/lib/api/node.js:96:9)
    at exports.default (/home/user/project/node_modules/babel-plugin-object-assign/lib/index.js:11:10)
    at Function.memoisePluginContainer (/home/user/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:109:13)
    at Function.normalisePlugin (/home/user/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:142:32)
    at /home/user/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:180:30
    at Array.map (native)
    at Function.normalisePlugins (/home/user/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:154:20)
    at OptionManager.mergeOptions (/home/user/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:229:36)
    at OptionManager.init (/home/user/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:374:12)
    at File.initOptions (/home/user/project/node_modules/babel-core/lib/transformation/file/index.js:216:65)
    at new File (/home/user/project/node_modules/babel-core/lib/transformation/file/index.js:139:24)
    at Pipeline.transform (/home/user/project/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
    at Babelify._flush (/home/user/project/node_modules/babelify/index.js:27:24)
    at Babelify.<anonymous> (_stream_transform.js:118:12)
    at Babelify.g (events.js:291:16)
    at emitNone (events.js:86:13)

Error, when changing to plugins: ['es6-object-assign'], probably because babelify requires the original object-assign package in node_modules/babelify/index.js on line var assign = require("object-assign");:

GET / 304 280.365 ms
Error thrown for request: /js/Application.js
Error: Plugin 0 specified in "base" provided an invalid property of "assign" while parsing file: /home/user/project/client/scripts/Application.js
    at Plugin.init (/home/user/project/node_modules/babel-core/lib/transformation/plugin.js:131:13)
    at Function.normalisePlugin (/home/user/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:148:12)
    at /home/user/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:180:30
    at Array.map (native)
    at Function.normalisePlugins (/home/user/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:154:20)
    at OptionManager.mergeOptions (/home/user/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:229:36)
    at OptionManager.init (/home/user/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:374:12)
    at File.initOptions (/home/user/project/node_modules/babel-core/lib/transformation/file/index.js:216:65)
    at new File (/home/user/project/node_modules/babel-core/lib/transformation/file/index.js:139:24)
    at Pipeline.transform (/home/user/project/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
    at Babelify._flush (/home/user/project/node_modules/babelify/index.js:27:24)
    at Babelify.<anonymous> (_stream_transform.js:118:12)
    at Babelify.g (events.js:291:16)
    at emitNone (events.js:86:13)
    at Babelify.emit (events.js:185:7)
    at prefinish (_stream_writable.js:478:12)
loganfsmyth
  • 156,129
  • 30
  • 331
  • 251
Peter G.
  • 7,816
  • 20
  • 80
  • 154
  • 1
    https://www.npmjs.com/package/babel-plugin-transform-object-assign – cartant Jan 03 '17 at 11:26
  • The `index.js` in `babelify` defines assign as `var assign = require("object-assign");` instead of `Object.assign(a, b);`. `babel-plugin-transform-object-assign` does not detect this pattern and does not replace anything. (as explained here https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-object-assign#caveats) – Peter G. Jan 03 '17 at 13:28

0 Answers0