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

Module build failed: TypeError: this._init is not a function #409

Closed
ralbatross204 opened this issue Oct 13, 2016 · 15 comments
Closed

Module build failed: TypeError: this._init is not a function #409

ralbatross204 opened this issue Oct 13, 2016 · 15 comments

Comments

@ralbatross204
Copy link

ralbatross204 commented Oct 13, 2016

I'm trying to build an electron app that will be using vue.js as well as electron-builder for final distribution. The electron-builder docs suggest using a two-package.json setup where the devDependencies are in the main package.json, and the dependencies are in app/package.json.

However, when I try to incorporate vue.js into this app, I run into problems because of this two-package.json setup. I get the following output when trying to run webpack:

[Vue warn]: Vue is a constructor and should be called with the new keyword 
Hash: a745e98e5605ad253bf8
Version: webpack 1.13.2
Time: 704ms
    Asset    Size  Chunks             Chunk Names
bundle.js  152 kB       0  [emitted]  main
    + 3 hidden modules

ERROR in ./app/components/MainScreen.vue
Module build failed: TypeError: this._init is not a function
    at Object.Vue$2 (/Users/rod/Innovative/projects/aglist/kiosk/varius-kiosk/app/node_modules/vue/dist/vue.common.js:2594:8)
 @ ./app/index.js 7:18-56

My index.js looks like this:

import Vue from 'vue'
import MainScreen from './components/MainScreen.vue'

new Vue({
    el: 'body',
    components: { MainScreen }
})

And the directory structure of the relevant files in my project looks like this:

/package.json (defines devDependencies)
/webpack.config.json  (uses app/index.js as the entry)
/app/package.json (defines dependencies)
/app/index.js

Commenting out the import MainScreen line results in webpack running successfully.
Another configuration where webpack works is if I move vue from a dependency in app/package.json to the main package.json, and also remove vue from the app/node_modules folder. This is not acceptable, though, because I need vue as a dependency in app/package.json in order to do make my app installers. If I have vue as a dependency in both package.json and app/package.json I still get the error above, even if I explicitly import Vue from '../node_modules/vue' in index.js. (IE, webpack seems to be using /app/node_modules/vue rather than /node_modules/vue)

Am I missing something here? Could anyone help me configure this so I can use both vue.js with webpack, and electron-builder with its two-package.json setup?

This issue is related to #171 which was closed due to inactivity.

@delta77x
Copy link

I had a similar situation - looks like webpack is using vue itself for loader instead of vue-loader in this case.
I resolved this type of problem by changing loader:'vue' to loader: 'vue-loader' in webpack.config:

loaders: [
  {
    test: /\.vue$/,
    loader: 'vue-loader'
  }, ...

@DearVikki
Copy link

@delta77x Your answer saved my afternoon!! Thx!! :D

@davewood
Copy link

I just had the same issue. changing to vue-loader in webpack config helped.

@Alvyre
Copy link

Alvyre commented Nov 15, 2016

@delta77x you saved my day ! thanks !

@rudidev08
Copy link

This was it - *-loader is no longer optional with webpack. Changing vue to vue-loader fixed this

@kazupon
Copy link
Member

kazupon commented Jan 6, 2017

Close
I think that solution said by rudidev08.

@alexkcode
Copy link

@rudidev08 any idea why it was ever optional anyway?

@ghost
Copy link

ghost commented Feb 19, 2017

I got this error in another way, so for anyone else who finds this and the above solution does not solve the error....

I got the error by accidentally importing vue twice which consequently instantiated vue twice.

So in my main app I had

import Vue from 'vue'

const app = new Vue({
    // stuff ...
})

and then in another file that instantiated my router

import VueRouter from 'vue' // <-- This was the typo. Should have been 'vue-router'

export default new VueRouter({
    // stuff ...
})

@Protossoario
Copy link

Protossoario commented Mar 3, 2017

For anyone coming here from Google, I was having the same issue when trying to inject dependencies into a Vue component, using the official webpack template for unit tests. I also solved it by changing this line:

const injector = require('!!vue?inject!@/components/MyComponent')

For the following:

const injector = require('!!vue-loader?inject!@/components/MyComponent')

The key is to replace vue with vue-loader, as stated above by @delta77x.

@gabengcuiyeye
Copy link

@delta77x thanks!!!

xalexec pushed a commit to Transnal/vue-loader that referenced this issue Mar 26, 2017
kiltec added a commit to kiltec/vuetable-2 that referenced this issue May 28, 2017
@Corbusier
Copy link

@delta77x thanks a lot,save my day!!!

@KMPolakowski
Copy link

Hey, I have the same problem, but cannot find anything about loader: vue (or rule) in the webpack configs of laravel-mix. Please help
I actualy get this: "TypeError: this._router.init is not a function"

@CristinaGuan
Copy link

I have already changed loader:'vue' to loader: 'vue-loader' in webpack.config,but this problem can not be solved

@sharkykh
Copy link

sharkykh commented Aug 5, 2018

For anyone having this error, looks like regenerating yarn.lock by removing the file then reinstalling the packages fixes the issue. Thanks to this comment.

@masashi49
Copy link

masashi49 commented Nov 12, 2018

私はこのように記述することで回避しました

const router = new VueRouter({   // not export default new VueRouter
      routes: [
    { ....
    }
  ]
});

export default router

binary4oul added a commit to binary4oul/vue2table-laravel5.4 that referenced this issue Mar 20, 2023
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