championswimmer / vuex-module-decorators

TypeScript/ES7 Decorators to create Vuex modules declaratively
https://championswimmer.in/vuex-module-decorators/
MIT License
1.8k stars 170 forks source link

Class constructor VuexModule cannot be invoked without 'new' #11

Closed abdullaev closed 6 years ago

abdullaev commented 6 years ago

"Class constructor VuexModule cannot be invoked without 'new'"

The problem exists in 0.5.0 release, with 0.4.3 everything is ok

championswimmer commented 6 years ago

Can you show the code ?

abdullaev commented 6 years ago

It's example with counter from README

jculverwell commented 6 years ago

Just upgraded to 0.5.0 and I'm also getting this. I think a full working sample application in this repo would be extremely useful.

bederuijter commented 6 years ago

I'm experiencing the same issues after upgrading to 0.5.0

@Module({ namespaced: true })
export class VacationCalendarVuexModule extends VuexModule {
    ...
}

it produces the following error

Uncaught TypeError: Class constructor VuexModule cannot be invoked without 'new'
    at new VacationCalendarVuexModule (vacation-calendar.ts:78)
    at Object.stateFactory (stateFactory.js:4)
    at stateFactory (index.js:8)
    at eval (index.js:10)
    at __decorate (vacation-calendar.ts:40)
    at eval (vacation-calendar.ts:137)
    at Object../ClientApp/store/modules/vacation-calendar.ts (bootstrap:791)
    at __webpack_require__ (bootstrap:724)
    at fn (bootstrap:101)
    at eval (index.ts:7)

Inspecting the line at vacation-calendar.ts:78 for me shows this

_this = _possibleConstructorReturn(this, _getPrototypeOf(VacationCalendarVuexModule).apply(this, arguments));

specifically the .applyseems to be failing.

"@babel/core": "^7.0.0-beta.54",
"@babel/plugin-proposal-class-properties": "^7.0.0-beta.54",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.54",
"@babel/plugin-transform-runtime": "^7.0.0-beta.54",
"@babel/polyfill": "^7.0.0-beta.54",
"typescript": "^3.0.3",
"vue": "^2.5.16",
"vuex": "^3.0.1",
"vuex-class": "^0.3.1",
Yongd commented 6 years ago

the same issue,look forward to come out a solution

championswimmer commented 6 years ago

most likely to work fine with v0.6.0

championswimmer commented 6 years ago

I think this is a very good example of how to use https://github.com/Armour/vue-typescript-admin-template

KleinMaximus commented 6 years ago

This error also occurs when use version 0.6.0

Yongd commented 6 years ago

yes, the error occurs at version 0.6.0 as the same

championswimmer commented 6 years ago

Can you guys show me your webpack/rollup configs ? I feel this is a es6 -> es5 transpilation level issue

championswimmer commented 6 years ago

v0.7.1 really totally fixes this. I finally figured out what the issue was

KleinMaximus commented 5 years ago

v0.8.0 - all ok v0.9.0 - occurs this error (Class constructor VuexModule cannot be invoked without 'new')

championswimmer commented 5 years ago

You need to transpile this module.

The README tells how to transpile dependencies via babel. I distribute it as ES6. If your target is ES5, you should transpile.

On Tue 30 Oct, 2018, 4:24 AM Nikolay Maksimov, notifications@github.com wrote:

v0.8.0 - all ok v0.9.0 - occurs this error (Class constructor VuexModule cannot be invoked without 'new')

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/championswimmer/vuex-module-decorators/issues/11#issuecomment-434110611, or mute the thread https://github.com/notifications/unsubscribe-auth/ABQ_yuSxL3BAx0mOj9KOpmcjQGAeDTArks5up4cIgaJpZM4WaotK .

ruifigueira commented 5 years ago

I had the same issue, I even tried transpileDependencies: ['vuex-module-decorators'] but it didn't work.

I had to use 0.8.0 version instead (thanks @KleinMaximus!).

championswimmer commented 5 years ago

are you using Typescript only or Typescript + Babel setup ?

ruifigueira commented 5 years ago

Typescript + Babel (I used vue-cli for the setup).

mastrayer commented 5 years ago

I have same issue. My TS transpile option is 'esnext'. and i had 0.9.0 version. but i set transpileDependencies: ['vuex-module-decorators'], then it's works.

championswimmer commented 5 years ago

@ruifigueira In that case

transpileDependencies: ['vuex-module-decorators'] 

in your vue.config.js should work

aceven24 commented 5 years ago

I have 0.9.0 installed and I tried adding this to my vue.config.js

module.exports = { transpileDependencies: ['vuex-module-decorators'] }

still get the error and my tsconfig looks like this:

{ "compilerOptions": { "target": "esnext", "module": "esnext", "strict": true, "jsx": "preserve", "importHelpers": true, "moduleResolution": "node", "experimentalDecorators": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "sourceMap": true, "baseUrl": ".", "types": [ "webpack-env", "mocha", "chai", "vuetify" ], "paths": { "@/": [ "src/" ] }, "lib": [ "esnext", "dom", "dom.iterable", "scripthost" ] }, "include": [ "src//*.ts", "src/*/.tsx", "src//*.vue", "tests/*/.ts", "tests/*/.tsx" ], "exclude": [ "node_modules" ] }

aceven24 commented 5 years ago

And FYI 0.8.0 works, no issues.

KleinMaximus commented 5 years ago

transpileDependencies: ['vuex-module-decorators'] works for me

shishkinilya commented 5 years ago

@championswimmer what i have to do if I dont use vue-cli and my tsconfig target is es5?

championswimmer commented 5 years ago

Depending on your tool you need to make sure your transpiler transpiles this module vuex-module-decorators too.

If ES5 support is not utterly essential, you can make your entire project target es2015, in which case the library will work as it is.

aceven24 commented 5 years ago

@KleinMaximus with .90?

@championswimmer this is all I have in my vue.config.js

module.exports = { transpileDependencies: ['vuex-module-decorators'] }

Armour commented 5 years ago

I also meet this problem when updating my code, add transpileDependencies: ['vuex-module-decorators'] fix it.

https://github.com/Armour/vue-typescript-admin-template now is with the latest version of vuex-module-decorators

Dids commented 5 years ago

@aceven24 Did you ever solve this? I just created a new TypeScript project with the latest Vue CLI yesterday, and whether or not I set transpileDependencies in my vue.config.js makes no difference.

EDIT: Never mind, it does work. Ended up being a caching issue. Do note that you'll also need babel.config.js for transpileDependencies to work.

championswimmer commented 5 years ago

Everyone please vote here https://github.com/championswimmer/vuex-module-decorators/issues/68

Need your opinions