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/ts - separation of concerns (vue-cli 3 beta 15) #1576

Closed
bc3 opened this issue Jun 14, 2018 · 5 comments
Closed

vue/ts - separation of concerns (vue-cli 3 beta 15) #1576

bc3 opened this issue Jun 14, 2018 · 5 comments

Comments

@bc3
Copy link

bc3 commented Jun 14, 2018

Version

3.0.0-beta.15

Reproduction link

https://codesandbox.io/s/j1wvnyn68w

Steps to reproduce

setup a new cli project using beta 15 & ui

add Test.vue

<template>
  <div>
      <p>TEST</p>
  </div>
</template>
<script lang="ts">
export { default } from './Test';
</script>

add Test.ts

import Vue from 'vue';
import { Component } from 'vue-property-decorator';
@Component({
    name: 'test',
    components: {

    },
})
export default class Test extends Vue {
}

and in the router change the home route to this test component or add another router

e.g. your app.ts

<template>
  <div id="app">
    <test/>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import * as Test from '@/components/Test.vue';

@Component({
  components: {
    Test,
  },
})
export default class App extends Vue {}
</script>

What is expected?

that the page is rendered and test is displayed

What is actually happening?

componentNormalizer.js?2877:24 Uncaught TypeError: Cannot set property 'render' of undefined
at normalizeComponent (componentNormalizer.js?2877:24)
at eval (Test.vue?2500:8)
at Module../src/components/Test.vue (app.js:3768)
at webpack_require (app.js:722)
at fn (app.js:99)
at eval (index.ts:6)
at Module../src/router/index.ts (app.js:3816)
at webpack_require (app.js:722)
at fn (app.js:99)
at eval (main.ts:6)


when using the ts code inside the vue file it works as expected, but i want to have a split vue and ts file

@coldino
Copy link

coldino commented Jun 15, 2018 via email

@yyx990803
Copy link
Member

FYI you can just do <script lang="ts" src="./Test.ts"></script>

@bc3
Copy link
Author

bc3 commented Jun 15, 2018

hey thanks for the 2 answers both work, but you will also need to add the ts-loader as a dev dependency. What i find weird since alle webpack loaders were removed from the packages, could that mean that the ts-loader was not added when using the vue-ui ?
I would however go with the solution of Evan, since that means I do not need to rename all my ts files. And i find it very clean to have a xxx.vue and a xxx.ts file next to each other

@coldino
Copy link

coldino commented Jun 20, 2018

If I try using Evan's solution I can no longer import the .vue from other files without editor- and built-time errors. The app still works, however. I'm using VSCode with Vetur and TSLint extensions.

I've made a small repro to show the problem: https://github.com/coldino/test-vue-script-import
It moves the code from HelloWorld.vue out to HelloWorld.ts. I get the same error if I use a different name for the TypeScript file.

npm run serve output:

ERROR in C:/Work/Temp/test-vue-script-import/src/App.vue
10:24 File 'C:/Work/Temp/test-vue-script-import/src/components/HelloWorld.vue' is not a module.
     8 | <script lang="ts">
     9 | import { Component, Vue } from 'vue-property-decorator';
  > 10 | import HelloWorld from './components/HelloWorld.vue';
       |                        ^
    11 |
    12 | @Component({
    13 |   components: {
ERROR in C:/Work/Temp/test-vue-script-import/src/views/Home.vue
10:24 File 'C:/Work/Temp/test-vue-script-import/src/components/HelloWorld.vue' is not a module.
     8 | <script lang="ts">
     9 | import { Component, Vue } from 'vue-property-decorator';
  > 10 | import HelloWorld from '@/components/HelloWorld.vue'; // @ is an alias to /src
       |                        ^
    11 |
    12 | @Component({
    13 |   components: {
No lint errors found
Version: typescript 2.9.2, tslint 5.10.0

I didn't understand the comment about ts-loader needing to be added to the dev dependencies. It's already picked up indirectly via @vue/cli-plugin-typescript and adding it myself makes no difference. Is there some extra config needed that I can't find?

@Akryum Akryum added bug scope: typescript needs team repro We acknowledged your report and will soon try to reproduce it labels Jun 28, 2018
@LinusBorg LinusBorg removed the needs team repro We acknowledged your report and will soon try to reproduce it label Jul 3, 2018
@LinusBorg
Copy link
Member

LinusBorg commented Jul 5, 2018

It seems that this issue is actually a duplicate of this one: #1104, and the source of the problem is found upstream in fork-ts-checker-webpack-plugin.

We already opened an issue, but a solution is not in immediate sight.

A workaround is described here: TypeStrong/fork-ts-checker-webpack-plugin#111 (comment)

Further discussion should be happening in the original issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants