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

Calling instance method from getter in VueSingleFileComponent causes error: Cannot find module #47

Closed
Buntelrus opened this issue Nov 29, 2020 · 6 comments · Fixed by #48

Comments

@Buntelrus
Copy link

I've a vue 3 project with typescript and I'm trying to get ts-transformer-keys work.

My configuration:

tsconfig.json:

"plugins": [
      { "transform": "ts-transformer-keys/transformer" }
]

vue.config.js

chainWebpack: config => {
    ['ts', 'tsx'].forEach(rule => {
      config.module
        .rule(rule)
        .use('ts-loader')
        .tap(options => Object.assign(options, {
          compiler: 'ttypescript',
          transpileOnly: false
        }))
    })
  }

I could locate the issue in the following problem:
If I call an instance method from a getter I got an error

Error: Cannot find module 'C:\path\src\App.vue.ts'

Without ts-transformer-keys this works fine.

For Example:
App.vue:

<template>
  <p>{{ message }}</p>
  <p>{{ messageAlias }}</p>
  <p>{{ upperCaseMessage }}</p>
  <p>{{ messageToUpperCase }}</p>
</template>

<script lang="ts">
import { Vue } from 'vue-class-component'
export default class App extends Vue {
  message = 'hello World'

  get messageAlias() {
    return this.message
  }

  get upperCaseMessage() {
    // return this.message.toUpperCase() // this will work
    return this.messageToUpperCase() // this won't
  }

  messageToUpperCase() {
    return this.message.toUpperCase()
  }
}
</script>
@kimamula
Copy link
Owner

Could you provide a repository that can reproduce the problem?
I have tried to reproduced your problem but encountered a different error.

ERROR in src/App.vue:9:10
TS2614: Module '"../node_modules/vue-class-component/lib"' has no exported member 'Vue'. Did you mean to use 'import Vue from "../node_modules/vue-class-component/lib"' instead?
     7 | 
     8 | <script lang="ts">
  >  9 | import { Vue } from 'vue-class-component'
       |          ^^^
    10 | export default class App extends Vue {
    11 |   message = 'hello World'
    12 | 

@Buntelrus
Copy link
Author

https://github.com/Buntelrus/ts-transformer-keys_issues_47 here you go.

The relevant code is in src/App.vue

kimamula added a commit that referenced this issue Dec 2, 2020
@kimamula
Copy link
Owner

kimamula commented Dec 2, 2020

@Buntelrus Thanks for reporting. Fixed in v0.4.3.

@Buntelrus
Copy link
Author

Buntelrus commented Dec 2, 2020

thank you

@Buntelrus
Copy link
Author

If I try to build my project I got now following error in the browser console:
image

while vue-cli-service serve has no issue. You can reproduce the problem with the mentioned repo.

@kimamula
Copy link
Owner

kimamula commented Dec 3, 2020

When I tried yarn build --mode development, it worked fine. I guess some build setting that is specific to production is preventing the transformer from working properly.

A similar problem was found before. But this time onlyCompileBundledFiles does not seem to be the cause of the problem as specifying onlyCompileBundledFiles: false does not help.

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

Successfully merging a pull request may close this issue.

2 participants