Vue-loader: vue components use CommonJS 'module.exports'

Created on 2 Jun 2018  Â·  10Comments  Â·  Source: vuejs/vue-loader

Version

13.7.0

Steps to reproduce

in vue component file, if i use the commonjs way to export

// error way
module.exports = {
    name: 'component-name'
}

// normal write
export default {

}

Because of some historical writing

What is expected?

compile is ok.

What is actually happening?

find error


21:2-16 "export 'default' (imported as '__vue_script__') was not found in '!!babel-loader!../../../node_modules/vue-loader/lib/selector?type=script&index=0!./component-upload.vue'

Most helpful comment

Is anyway to support module.exports in vue-cli3 created project ?
Because I would like to share some common module with frontend and backend.

All 10 comments

It should be module.exports instead of module.export.

@Justineo Sorry, writing error, got change.

See breaking changes in v13.0.0.

old CommonJS-style requires will also need to be updated:

// before
const Foo = require('./Foo.vue')

// after
const Foo = require('./Foo.vue').default

BTW, I think you can upgrade your vue-loader to the 14 or higher version. because from v14.0.0

esModules option has been removed. Built module is now always exposed as an ES module.

@ulivz vue-loader has been updated to v14.1.0, question is still.
so i need to do something for babel in vue-loader config ?

Could you provide your webpack's version? or it would be better to also provide a minimal reproduction repo link.

@ulivz use the vue-cli webpack config, webpack version is 3.6.0

14.0+ no longer supports module.exports. Use export default instead.

@yyx990803 I have a library that requires this logic to pass
typeof module.exports !== 'undefined'

No matter what I try, it is always undefined :(
I am sure it is a Webpack fix instead of Vue, but just in case, any advice?

Is anyway to support module.exports in vue-cli3 created project ?
Because I would like to share some common module with frontend and backend.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

flashios09 picture flashios09  Â·  3Comments

matt-sanders picture matt-sanders  Â·  4Comments

Makio64 picture Makio64  Â·  4Comments

chrisvfritz picture chrisvfritz  Â·  4Comments

TheVexatious picture TheVexatious  Â·  3Comments