Search code examples
npmbrowserifyvue.jslaravel-elixir

Vueify can't require component from node_modules


Here's my npm package

First, I install it.

npm install asva-vue-filters

Then I require the package from javascript file:

var vueFilters = require('asva-vue-filters')

And for some reason I get spammed by errors such as the following one (for every *.vue file in package):

gulp-notify: [Laravel Elixir] 
Browserify Failed!: Parsing file c:\homestead\pr5\node_modules\
asva-vue-filters\components\filters\sorting-order-filter.vue: 
Unexpected token (1:0)

But if I just copy the package folder from node_modules to some other place (e.g. project root), then I can require and everything works.

// Doesn't work
var vueFilters = require('./../../../../node_modules/asva-vue-filters/index')
// Works
var vueFilters = require('./../../../../asva-vue-filters/index')

Any ideas? Help is much appreciated.


Solution

  • I managed to solve an issue and here is how:

    1. Remove require('laravel-elixir-vueify') from gulpfile.js.
    2. Add browserify transforms to you package's package.json:
        "browserify": {
          "transform": [
            [
              "babelify",
              {
                "presets": [
                  "es2015"
                ]
              }
            ],
            [
              "vueify"
            ]
          ]
        },
    

    Alternatively, you can prepublish your package into digestible bundle that doesn't require browserify to function.