Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

export default {} works differently than module.exports = {} #5

Open
Skysplit opened this issue Oct 2, 2016 · 5 comments
Open

export default {} works differently than module.exports = {} #5

Skysplit opened this issue Oct 2, 2016 · 5 comments

Comments

@Skysplit
Copy link

Skysplit commented Oct 2, 2016

When using exports default { ... }, require('./components/Example.vue') returns object with default key as content.

export default {
    data() {
        return {
            counter: 0
        }
    },
    methods: {
        increment() {
            this.counter += 1
        }
    }
}

Returns

{
    computed: Object,
    default: {
        ready: function data() {},
        methods: Object,
    }
}

module.exports = {
    data() {
        return {
            counter: 0
        }
    },
    methods: {
        increment() {
            this.counter += 1
        }
    }
}

Returns

{
    computed: Object,
    ready: function ready() {},
    methods: Object
}

Shouldn't these two examples work the same way?

@Skysplit Skysplit changed the title exports default {} breaks code exports default {} works differently than module.exports = {} Oct 2, 2016
@Skysplit Skysplit changed the title exports default {} works differently than module.exports = {} export default {} works differently than module.exports = {} Oct 2, 2016
@adifaidz
Copy link

adifaidz commented Nov 1, 2016

This occurred to me when I changed from laravel-elixir-vue to laravel-elixir-vue-2. My components props were not set. When I changed exports default to module.exports it works. Weirdly enough, on laravel-elixir-vue, exports default works just fine. 😞

@osiux
Copy link

osiux commented Nov 4, 2016

I think it's the same thing as in JeffreyWay/laravel-elixir-vue#10

For this to work this package would need to use babel loader for .js files and add "babel-plugin-add-module-exports" as dependency, although the current ES proposal is using "default" as in require('./components/Example.vue').default, or that's why I understand (not versed on node/js enviroment).

@adifaidz
Copy link

adifaidz commented Nov 4, 2016

@osiux Thanks for the response, will try and confirm the results later 👍

@nbyloff
Copy link

nbyloff commented Jan 6, 2017

Checking in to report that going from vue 1 to 2 after following the vue 1 laracasts, I had to change all my single file components to module.exports from exports default.

exports default no longer worked for me either; none of my properties came up defined.

@adifaidz
Copy link

adifaidz commented Jan 10, 2017

@osiux I can't seem to get that done lol ( I'm also not versed on node) 😆 . But what I can confirm is that after getting a fresh laravel 5.3, it works out of the box for me. Maybe this didn't work because there is an issue with migrating from vue 1 to vue 2. I can only assume that's the case because laravel 5.3 came with vue 2 support

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants