meteor-vue2-example icon indicating copy to clipboard operation
meteor-vue2-example copied to clipboard

Error with 'setDefault' in app.vue

Open AsafAgranat opened this issue 7 years ago • 4 comments

I cloned the example and followed all the add, remove and npm instructions mentioned in the Readme.md. On first run it throws the following error:

 Exited with code: 1
.....meteor\packages\meteor-tool\1.4.3_2\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:280
throw(ex);
TypeError: Cannot read property 'setDefault' of undefined
 at imports/ui/App.vue:27:1

Not sure what's causing it. Perhaps something changed in the recent Session package? I changed the faulting line from to: Session.setDefault("counter", 0) to: Session.set("counter", 0) which made the app run fine.

UPDATE I changed it back to the orginal Session.setDefault("counter", 0), but I moved it into the 'beforeCreate' lifecycle hook, and that seems to work fine.

AsafAgranat avatar Mar 14 '17 16:03 AsafAgranat

I have same issue. What exactly I need to do when you said " I moved it into the 'beforeCreate' lifecycle hook, and that seems to work fine." ?

imkebe avatar Mar 19 '17 15:03 imkebe

export default {
...
    beforeCreate(){
       Session.setDefault("counter", 0);
    },
...
};

AsafAgranat avatar Mar 19 '17 16:03 AsafAgranat

I get this error too. It looks like App.vue is being run on the server, and Session is a client only package. Any thoughts?

jonathan82 avatar May 18 '17 04:05 jonathan82

Facing the same issue as well. Here's what I have in my meteor packages:

# Meteor packages used by this project, one per line.
# Check this file (and the other files in this directory) into your repository.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.

[email protected]             # Packages every Meteor app needs to have
[email protected]       # Packages for a great mobile UX
[email protected]                   # The database Meteor supports right now
[email protected] # Compile .html files into Meteor Blaze views
[email protected]            # Reactive variable for tracker
[email protected]                 # Meteor's client-side reactive programming library

[email protected]   # CSS minifier run for production mode
[email protected]    # JS minifier run for production mode
[email protected]                # ECMAScript 5 compatibility for older browsers
[email protected]              # Enable ECMAScript2015+ syntax in app code
[email protected]            # Server-side component of the `meteor shell` command

[email protected]             # Publish all data to the clients (for prototyping)
[email protected]                # Allow all DB writes from clients (for prototyping)
akryum:vue-component
[email protected]

And this is what's in my App.vue:

<template>
	<div id="root">
		<h1>Sample first page</h1>
		<p>you should appear</p>
	</div>
</template>

<script>
	import { Session } from 'meteor/session';

	export default {
		beforeCreate() {
			Session.setDefault('counter', 0);
		},
		data() {
			return {
				count: 0,
			}
		},
		meteor: {
			data: {
				count() {
					return Session.get('counter');
				},
			}
		},
		methods: {
			increment() {
				Session.set('counter', this.count + 1)
			},
		}
	};
</script>

Hope this helps.

@AsafAgranat thanks for the fix. It works for me as well :)

gczh avatar Jun 14 '17 22:06 gczh