Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Object.getOwnPropertyNames called on non-object #332

Open
lcaprini opened this issue Dec 8, 2020 · 0 comments
Open

Comments

@lcaprini
Copy link

lcaprini commented Dec 8, 2020

Hi, I'm starting to use Vue and Vuex with typescript in a new project, but I need to support very old browser (Chrome >= 38), so I need to transpile into ES5.

I'm using VueJS 2.x because the new 3.x doesn't support transpiling to ES5 and all works fine, except for your package: during the initialization the app throws the error Uncaught TypeError: Object.getOwnPropertyNames called on non-object when executes addGettersToModule function. No errors on new browsers.

On https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames I found the following:

In ES5, if the argument to this method is not an object (a primitive), then it will cause a TypeError. In ES2015, a non-object argument will be coerced to an object.

My files:

// config.state.ts
import { RPConfig } from './config.model';
export class ConfigState {
    public config: RPConfig | null = null;
}

// config.module.ts
import axios from 'axios';
import {
    Module,
    VuexModule,
    MutationAction,
    getModule
} from 'vuex-module-decorators';
import { RPConfig } from './models/config.model';
import { RPConfigDTO } from './models/config.dto';
import { ConfigState } from './models/config.state';
import store from '@/store';

@Module({ dynamic: true, name: 'config ', store })
class RPConfigModule extends VuexModule implements ConfigState {
    config: RPConfig | null = null;

    /**
     * Verifica se il configuratore è stato scaricato
     * @returns boolean
     */
    get configIsReady(): boolean {
        return this.config !== undefined;
    }

    /**
     * RItorna la base URL della CDN
     * @returns string
     */
    get cdnBaseUrl(): string {
        return this.config ? this.config.cdnBaseUrl : '';
    }

    @MutationAction
    update(payload: { configUrl: string }): Promise<{ config: RPConfig }> {
        const { configUrl } = payload;
        return new Promise((resolve, reject) => {
            axios.get<RPConfigDTO>(configUrl).then(
                (response) => {
                    resolve({
                        config: RPConfig.fromConfigDTO(response.data)
                    });
                },
                (err) => {
                    console.log(err);
                    setTimeout(() => {
                        this.update(payload).then(resolve, reject);
                    }, 5000);
                }
            );
        });
    }
}
export const RPConfigState = getModule(RPConfigModule);

// store.ts
import Vue from 'vue';
import Vuex from 'vuex';
import { ConfigState } from './config/models/config.state';

export interface RootState {
    config: ConfigState;
}
Vue.use(Vuex);
export default new Vuex.Store<RootState>({});

Could you help me to solve that issue?
Thanks?

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

No branches or pull requests

1 participant