Git Product home page Git Product logo

Comments (9)

jvbianchi avatar jvbianchi commented on May 27, 2024 1

With relative path I got this error:

error TS2307: Cannot find module './../components/MyComponent.vue'.

import:

import MyComponent from "./../components/MyComponent.vue"

from typescript-template.

Atinux avatar Atinux commented on May 27, 2024

Does it work by importing with a relative path instead of the alias ~components?

from typescript-template.

jvbianchi avatar jvbianchi commented on May 27, 2024

I tried also importing without the vue extension:

import MyComponent from "./../components/MyComponent"

error:

error TS2307: Cannot find module './../components/MyComponent'.

from typescript-template.

johnlindquist avatar johnlindquist commented on May 27, 2024

Thanks for taking a look @Atinux

I don't quite understand appendTSSuffixTo:
https://github.com/TypeStrong/ts-loader#appendtssuffixto-regexp-default

Also, every example I've read through uses esModule:true on the vue-loader:
https://github.com/vuejs/vue-class-component/blob/master/example/webpack.config.js#L24

I just don't have that much webpack experience, so trying to override the build config in nuxt.config.js just turns into guessing for me.

from typescript-template.

jvbianchi avatar jvbianchi commented on May 27, 2024

Do you think adding typings like this:

declare module '*.vue' {
	import Vue = require('vue')
	const value: Vue.ComponentOptions<Vue>
	export default value
}

will have any effect?

from typescript-template.

johnlindquist avatar johnlindquist commented on May 27, 2024

@jvbianchi no, it's not a type error...

from typescript-template.

johnlindquist avatar johnlindquist commented on May 27, 2024

@jvbianchi Try something for me:

add a components/Foo.vue with the following contents:

<template>
  <div>
    Hi
  </div>
</template>
<script lang="ts">
export default {

}
</script>

import it in index.vue with

import Foo from "~components/Foo"

and make sure to add it to

@Component({
  components: {
    Foo
  },

If the dev server is running, stop then yarn dev again.

Tell me if that works...

I'm thinking I've seen the following behaviors:

  1. When you add a new component, you need to stop then restart the dev server
  2. If you import without actually using a component, it throws a "module not found". Do at least a console.log(Foo) makes this go away.
  3. I believe a .vue for TS need a minimal script tag that exports at least an object.

Those are bizarre behaviors IMO, but I don't have any answers...

from typescript-template.

jvbianchi avatar jvbianchi commented on May 27, 2024

@johnlindquist when you add:

<script lang="ts">
export default {

}
</script>

to any component it starts working.
I tested with:

import MyComponent from "./../components/MyComponent.vue"
import Foo from "~components/Foo.vue";

// and

import MyComponent from "./../components/MyComponent"
import Foo from "~components/Foo";

In both cases work as expected.

As you said:

  1. It works even without restarting the server.
  2. If you don't use the component I got the error:
error TS2307: Cannot find module './../components/Foo.vue'.

but if I console.log(Foo) it works.

from typescript-template.

johnlindquist avatar johnlindquist commented on May 27, 2024

Great, thanks for the help.

from typescript-template.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.