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.

TypeError: Class constructor BaseModel cannot be invoked without 'new'

See original GitHub issue

Steps to reproduce

Using v2.0.0-pre.62 (for real this time 😎). I’m getting the error TypeError: Class constructor BaseModel cannot be invoked without 'new'. The error is being thrown at service-module.actions.ts#L277.

I put a break in at that line in the code and found that the fetch operation is successful. An array of objects has been returned by the API and the error happens when trying to convert them into model instances. This Stack Overflow post suggests that the issue may be caused by the Babel target preset. It indicates that this preset should be changed from es2015 to node, but TBH, I am not comfortable or familiar enough with how Babel works to know if this is really the issue.

Here are the snippets of my current setup. The full repo is available here.

My Feathers client setup:

// src/services/api.js
import feathers from '@feathersjs/feathers'
import auth from '@feathersjs/authentication-client'
import feathersVuex from 'feathers-vuex'
import socketio from '@feathersjs/socketio-client'
import io from 'socket.io-client'

const app = feathers()
const socket = io(process.env.VUE_APP_API_URL)
app.configure(socketio(socket))

const api = app

const {
  makeServicePlugin,
  BaseModel,
  models,
  clients,
  FeathersVuex
} = feathersVuex(app, { serverAlias: 'api' })

export {
  api,
  FeathersVuex,
  BaseModel,
  clients,
  makeServicePlugin,
  models
}

My model class setup:

// src/store/services/artifacts.js
import { api, makeServicePlugin, BaseModel } from '@/services/api'

class Artifact extends BaseModel {
  static modelName = 'Artifact'
  // eslint-disable-next-line
  constructor (data, options) {
    super(data, options)
  }
  static instanceDefaults = () => ({
    createdAt: null,
    name: null,
    narrative: null,
    notes: [],
    status: 'draft',
    tags: [],
    updatedAt: null,
    uri: null,
    userId: null
  })
}

const servicePath = 'artifacts'
const servicePlugin = makeServicePlugin({
  Model: Artifact,
  service: api.service(servicePath),
  servicePath
})

export default servicePlugin

Store setup:

import Vue from 'vue'
import Vuex from 'vuex'
import { FeathersVuex } from 'feathers-vuex'
import { api as appAPI } from '@/services/api'
import auth from '@/store/modules/auth'
import common from '@/store/modules/common'
import user from '@/store/modules/user'

// register Vue plugins
Vue.use(Vuex)
Vue.use(FeathersVuex)

// passthrough export of key objects
export const api = appAPI

// get the API service plugins
const requireModule = require.context('@/store/services', false, /.js$/)
const apiPlugins = requireModule.keys().map(path => requireModule(path).default)

export const store = new Vuex.Store({
  strict: process.env.NODE_ENV !== 'production',
  modules: {
    // artifacts,
    auth,
    common,
    user
  },
  plugins: [
    ...apiPlugins
  ]
})

Finally, some snippets from the component that’s causing the error to be thrown (using <feathers-vuex-find>):

// src/components/pages/artifacts/TheArtifactsPage.vue
<template>
  ...
    <feathers-vuex-find
      :fetch-query="{ userId: $store.state.auth.apiId, $limit: -1 }"
      :query="query"
      service="artifacts"
    >
      <v-data-table
        slot-scope="{ items: artifacts }"
        :items="artifacts"
        item-key="_id"
      >
        ...
      </v-data-table>
    </feathers-vuex-find>
  ...
</template>

I’m hoping that I just have a configuration error somewhere. Changing the Babel config seems like it could have serious ripple effects.

  • Tell us what broke. The more detailed the better.
  • If you can, please create a simple example that reproduces the issue and link to a gist, jsbin, repo, etc.

Expected behavior

The retrieved artifacts should be displayed

Actual behavior

TypeError: Class constructor BaseModel cannot be invoked without 'new'

System configuration

Tell us about the applicable parts of your setup.

Module versions (especially the part that’s not working): v2.0.0-pre.62

NodeJS version: v10.15.3

Operating System: OSX 10.13.6 (High Sierra)

Browser Version: Chrome (mac) 75.0.3770.100

Module Loader: Vue v2.6.10, Vuex v3.1.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
marshallswaincommented, Jul 18, 2019

Basically, you need to add feathers-vuex to the transpileDependencies key in the vue.config.js file.

1reaction
apmcodescommented, Oct 22, 2019

Seems feathers-vuex was not installed properly or latest version. Removed it from package.json and did npm install --save and error went away.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Class constructor model cannot be invoked without ...
When I run my app, an error appears: TypeError: Class constructor model cannot be invoked without 'new' at line 17 which is the...
Read more >
Class constructor Model cannot be invoked without 'new' and ...
Hi all, I using v4 to defined my model as: @Options({ sequelize, tableName: 'V2_category', timestamps: false }) @Attributes({ id: { type: ...
Read more >
Angular script compilation: TypeError: Class constructor ...
TypeError : Class constructor MyScript cannot be invoked without 'new' at requireScriptForNodes (tools.ts:71) at attachScripts (tools.ts:220) ...
Read more >
angular/angular - Gitter
I get Cannot find a differ supporting object '[object Object]' of type ... TypeError: Class constructor InputMetadata cannot be invoked without 'new' ....
Read more >
TypeError: Class constructor NodeEnvironment cannot be ...
TypeError : Class constructor NodeEnvironment cannot be invoked without 'new' · MongoDB University M220JS: MongoDB for Javascript Developers.
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