question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Action with namespace: TypeError: Cannot redefine property

See original GitHub issue

When use Action with namespace, page will throw “TypeError: Cannot redefine property: …”

Part of codes like blow:

import Vue from 'vue'
import Component, {Getter, Action, namespace } from 'class-component'
const DemoGetter = namespace('demo', Getter)
const DemoAction = namespace('demo', Action)

@Component
export default class Demo extends Vue {
  @DemoAction selectCity
  @Getter authUser
  @DemoGetter city
}

According to my research, after vuex-class defined the actions on vm, vue “initMethods” will define all methods onto vm.

function initMethods (vm, methods) {
  var props = vm.$options.props;
  console.log('methods: ' +JSON.stringify( methods))
  for (var key in methods) {
    vm[key] = methods[key] == null ? noop : bind(methods[key], vm);
    if (process.env.NODE_ENV !== 'production') {
      if (methods[key] == null) {
        warn(
          "method \"" + key + "\" has an undefined value in the component definition. " +
          "Did you reference the function correctly?",
          vm
        );
      }
      if (props && hasOwn(props, key)) {
        warn(
          ("method \"" + key + "\" has already been defined as a prop."),
          vm
        );
      }
    }
  }
}

And then vue-class-component method ‘_init’ may redefine them again, so the error occurred.

Component.prototype._init = function () {
        var _this = this;
        var keys = Object.getOwnPropertyNames(vm);
        if (vm.$options.props) {
            for (var key in vm.$options.props) {
                if (!vm.hasOwnProperty(key)) {
                    keys.push(key);
                }
            }
        }
        keys.forEach(function (key) {
            if (key.charAt(0) !== '_') {
                Object.defineProperty(_this, key, {
                    get: function () { return vm[key]; },
                    set: function (value) { return vm[key] = value; }
                });
            }
        });
    };

Does this have any solution or pr?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
ktsncommented, Nov 3, 2017

Fixed via vue-class-component v6.1.0

0reactions
dimamarksmancommented, Nov 3, 2017

@ktsn Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: can't redefine non-configurable property "x"
The JavaScript exception "can't redefine non-configurable property" occurs when it was attempted to redefine a property, but that property is non-configurable.
Read more >
webpack-cli: TypeError: Cannot redefine property: tap
i'm receiving this error whenever i try to run npm run dev npm run development npm WARN config global `--global`, `--local` are deprecated....
Read more >
Configuring Jest
The function should either return a path to the module that should be resolved or throw an error if the module can't be...
Read more >
Ngrx example - ALCA Profumerie
Actions are dispatched via Store in NgRx and observed by NgRx's Reducers and Effects. ... Angular Universal TypeError: Cannot redefine property: [email ...
Read more >
Project Configuration File Format - Gerrit Code Review
The refs/meta/config namespace; Property inheritance; The file project.config ... You can also redefine the text and behavior of the built in label types ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found