Skip to content
This repository was archived by the owner on Dec 26, 2018. It is now read-only.
This repository was archived by the owner on Dec 26, 2018. It is now read-only.

Incorrect options object passed to babel from browserify cli #233

Open
@nolimitdev

Description

@nolimitdev

Vueify transform passes incorrect format of options object to babel...

$ browserify -t [ vueify --babel [ --presets [ env ] ] ] -e main.js -o build.js

ReferenceError: [BABEL] item.vue: Unknown option: foreign._. Check out http://babeljs.io/docs/usage/options/ for more information about options.
A common cause of this error is the presence of a configuration options object without the corresponding preset name.

Vueify in vueify/lib/compilers/babel.js passes options to babel.transform(raw, options) in wrong format presets: { _: [ 'env' ] } which is created by minimist via subarg in browserify instead of correct format presets: [ 'env' ].

For example babelify transform works well with the similar command:
$ browserify -t [ babelify --presets [ env ] ] -e main.js -o build.js
... this syntax comes directly from babelify doc at npmjs.com

In babelify it is working thanks to following code in babelify/index.js in Babelify.configure():

// browserify cli options
delete opts._;
if (opts.presets && opts.presets._) opts.presets = opts.presets._;

This issue can be fixed by adding following code in vueify/lib/compilers/babel.js:

// add this after line "`var babel = require('babel-core')"
var opts = compiler.options.babel
if (opts) {
  delete opts._
  // "--opt [ a b ]" and "--opt a --opt b" are allowed:
  if (opts.ignore && opts.ignore._) opts.ignore = opts.ignore._
  if (opts.only && opts.only._) opts.only = opts.only._
  if (opts.plugins && opts.plugins._) opts.plugins = opts.plugins._
  if (opts.presets && opts.presets._) opts.presets = opts.presets._
}

PR: #235

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions