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

Type Definitions broken in 2.3.0? #1202

Closed
eugirdor opened this issue Feb 26, 2017 · 9 comments
Closed

Type Definitions broken in 2.3.0? #1202

eugirdor opened this issue Feb 26, 2017 · 9 comments

Comments

@eugirdor
Copy link

Vue.js / vue-router versions

2.1.2 / 2.3.0

Reproduction Link

Steps to reproduce

Using Typescript 2.2.1 and Webpack 2.2.1

In VueRouter 2.2.1 importing was done with import VueRouter = require('vue-router') but it looks like in 2.3.0 it needs to be import VueRouter from 'vue-router'.

The issue is that it looks like the type definitions still define the export as export = VueRouter where it needs to be export default VueRouter now.

What is Expected?

Importing 'vue-router' the proper way should not give a compiler warning.

What is actually happening?

When Using: import VueRouter = require('vue-router')
You Get: Uncaught TypeError: VueRouter is not a constructor

When Using: import VueRouter from 'vue-router
You Get: Compiler warning that vue-router has no default export

@yyx990803
Copy link
Member

/cc @ktsn

@yyx990803
Copy link
Member

yyx990803 commented Feb 26, 2017

For now I think you can work around this by configuring a webpack alias pointing vue-router to vue-router/dist/vue-router.common.js instead?

@eugirdor
Copy link
Author

@yyx990803 Yes, that workaround works. Thanks.

@ktsn
Copy link
Member

ktsn commented Feb 26, 2017

This is because TypeScript treats module.exports = VueRouter and export default VueRouter as different things. We can fix this by defining static default property in VueRouter class in typings...

Also we need to update core's typings. I'll create some PRs.

@ktsn
Copy link
Member

ktsn commented Feb 26, 2017

Hmm, I found the above approach is problematic... If we declare default static property in VueRouter class to deal with both ESModules and commonjs, both import VueRouter from 'vue-router' and import VueRouter = require('vue-router') works but the former imported class does not allow inheritance. 😞

I think the most compromisable solution is to remove module field from package.json and let the users can select esm build by using alias like other build.

@HerringtonDarkholme Do you have any better idea to deal with this problem?

@yyx990803
Copy link
Member

yyx990803 commented Feb 26, 2017

If that's the case, I'd prefer supporting import X from 'x' by default instead. Users who want to keep using import X = require('x') will need to config the alias. <- is that even possible?

@HerringtonDarkholme
Copy link
Member

Hi, @eugirdor . For now you can use allowSyntheticDefaultImports to build app.

I think Vue typing will have a fix release.

@yyx990803
Copy link
Member

See updated TS integration docs: https://vuejs.org/v2/guide/typescript.html

@xingangsun
Copy link

@yyx990803

For now I think you can work around this by configuring a webpack alias pointing vue-router to vue-router/dist/vue-router.common.js instead?

Does this configuration support webpack2 tree-shaking?

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

5 participants