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

vue components use CommonJS 'module.exports' #1337

Closed
FeSeason opened this issue Jun 2, 2018 · 10 comments
Closed

vue components use CommonJS 'module.exports' #1337

FeSeason opened this issue Jun 2, 2018 · 10 comments

Comments

@FeSeason
Copy link

FeSeason commented Jun 2, 2018

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'
@Justineo
Copy link
Member

Justineo commented Jun 2, 2018

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

@FeSeason
Copy link
Author

FeSeason commented Jun 2, 2018

@Justineo Sorry, writing error, got change.

@ulivz
Copy link
Member

ulivz commented Jun 2, 2018

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

@ulivz
Copy link
Member

ulivz commented Jun 2, 2018

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.

@FeSeason
Copy link
Author

FeSeason commented Jun 2, 2018

@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 ?

@ulivz
Copy link
Member

ulivz commented Jun 2, 2018

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

@FeSeason
Copy link
Author

FeSeason commented Jun 4, 2018

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

@yyx990803
Copy link
Member

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

@EmilyRosina
Copy link

@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?

@sj82516
Copy link

sj82516 commented Aug 24, 2018

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

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

6 participants