Nuxt.js: class property does not work in v2.5.1

Created on 27 Mar 2019  路  4Comments  路  Source: nuxt/nuxt.js

Version

v2.5.1

Reproduction link

https://not-needed.com

Steps to reproduce

$ npx create-nuxt-app nuxt-app
$ cd nuxt-app

Modify /pages/index.vue.

<template>
  <section class="container">
    {{ name }}
  </section>
</template>

<script>
class Sample {
  static NAME = 'Alice'
}

export default {
  data() {
    return {
      name: Sample.NAME
    }
  }
}
</script>

Start Nuxt.js app

$ npm run dev

What is expected ?

Start the application and create the instance having data: {name: 'Alice'}.

What is actually happening?

Throw an Error: SyntaxError Unexpected token export

This bug report is available on Nuxt community (#c8946)
bug-report

All 4 comments

FYI銆乀his happens when mode is set to universal. Mode spa will work just fine.

Having the same problem. App crashes whenever I add properties to my classes.

A simple example here https://codesandbox.io/s/jv34jj5wl5

Switching mode to spa is not option for everyone.

@Arnique The PR to fix this issue was merged but the new version of Nuxt is not out yet. You need to wait until the next release.

@Arnique The PR to fix this issue was merged but the new version of Nuxt is not out yet. You need to wait until the next release.

Thanks for working on this.

For now I got it to work by installing babel-plugin-transform-class-properties and adding it in the config i.e

build: {
    babel: {
        plugins: ['babel-plugin-transform-class-properties']
    }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

pehbehbeh picture pehbehbeh  路  3Comments

o-alexandrov picture o-alexandrov  路  3Comments

uptownhr picture uptownhr  路  3Comments

shyamchandranmec picture shyamchandranmec  路  3Comments

vadimsg picture vadimsg  路  3Comments