Vue-cli: When I use ”#“ private method in class, it will not be compiled through and an error will be thrown: support for the experimental syntax 'classprivatemethods' isn't currently enabled . I can make sure that this problem occurs in the definition of private method. If you delete it, there will be no error

Created on 23 Mar 2020  ·  1Comment  ·  Source: vuejs/vue-cli

Version

4.2.3

Reproduction link

https://github.com/ccz-Eric/error-issues

Environment info

  npmPackages:
    @vue/babel-helper-vue-jsx-merge-props:  1.0.0 
    @vue/babel-plugin-transform-vue-jsx:  1.1.2 
    @vue/babel-preset-app:  4.2.3 
    @vue/babel-preset-jsx:  1.1.2 
    @vue/babel-sugar-functional-vue:  1.1.2 
    @vue/babel-sugar-inject-h:  1.1.2 
    @vue/babel-sugar-v-model:  1.1.2 
    @vue/babel-sugar-v-on:  1.1.2 
    @vue/cli-overlay:  4.2.3 
    @vue/cli-plugin-babel: ~4.2.0 => 4.2.3 
    @vue/cli-plugin-eslint: ~4.2.0 => 4.2.3 
    @vue/cli-plugin-router:  4.2.3 
    @vue/cli-plugin-vuex:  4.2.3 
    @vue/cli-service: ~4.2.0 => 4.2.3 
    @vue/cli-shared-utils:  4.2.3 
    @vue/component-compiler-utils:  3.1.1 
    @vue/preload-webpack-plugin:  1.1.1 
    @vue/web-component-wrapper:  1.2.0 
    eslint-plugin-vue: ^6.1.2 => 6.2.2 
    vue: ^2.6.11 => 2.6.11 
    vue-eslint-parser:  7.0.0 
    vue-hot-reload-api:  2.3.4 
    vue-loader:  15.9.0 
    vue-style-loader:  4.1.2 
    vue-template-compiler: ^2.6.11 => 2.6.11 
    vue-template-es2015-compiler:  1.9.1 
    vue-virtual-scroll-list: ^1.4.6 => 1.4.6 
    vuex: ^3.1.3 => 3.1.3 
  npmGlobalPackages:
    @vue/cli: 4.2.3

Steps to reproduce

Steps to reproduce the behavior:
class Foo { #a; #b; constructor(a, b) { this.#a = a; this.#b = b; } #sum() { return #a #b; } printSum() { console.log(this.#sum()); } }

What is expected?

Code works

What is actually happening?

Throw out error ”upport for the experimental syntax 'classprivatemethods' isn't currently enabled“


The following changes have been made, and error reporting cannot be resolved
package.json
"devDependencies": { "@babel/plugin-proposal-class-properties": "^7.8.3", ... },
babel.config.js
module.exports = { presets: [ '@vue/cli-plugin-babel/preset' ], plugins: [ "@babel/plugin-proposal-class-properties" ] }

Unfortunately, it doesn't solve the problem. We need help

Most helpful comment

You installed the wrong babel plugin. you want this:

https://babeljs.io/docs/en/babel-plugin-proposal-private-methods

>All comments

You installed the wrong babel plugin. you want this:

https://babeljs.io/docs/en/babel-plugin-proposal-private-methods

Was this page helpful?
0 / 5 - 0 ratings

Related issues

OmgImAlexis picture OmgImAlexis  ·  3Comments

sanderswang picture sanderswang  ·  3Comments

brandon93s picture brandon93s  ·  3Comments

Gonzalo2683 picture Gonzalo2683  ·  3Comments

eladcandroid picture eladcandroid  ·  3Comments