[英]Adding Typescript to Vue + Rails app - Imports no longer work?
I'm trying to add TypeScript to an existing VueJS + Rails app. 我正在尝试将TypeScript添加到现有的VueJS + Rails应用程序中。 I cloned this demo ( https://github.com/gbarillot/rails-vue-demo-app ) then followed the instructions from https://github.com/rails/webpacker
我克隆了此演示( https://github.com/gbarillot/rails-vue-demo-app ),然后按照https://github.com/rails/webpacker中的说明进行操作
$ bundle exec rails webpacker:install:vue
$ bundle exec rails webpacker:install:typescript
I then modified config/webpack/loaders/typescript.js
as described here . 然后,我按此处所述修改了
config/webpack/loaders/typescript.js
。
Everything seems to compile, but when I go into my "home" view and change the script
to typescript: 一切似乎都可以编译,但是当我进入“ home”视图并将
script
更改为打字稿时:
<script lang="ts">
import Layout from '../shared/layout';
export default {
components: {
Layout
}
}
</script>
I get the following error: 我收到以下错误:
Failed to compile.
/Users/matt/projects/rails-vue-demo-app/app/javascript/packs/components/home/index.vue.ts
[tsl] ERROR in /Users/matt/projects/rails-vue-demo-app/app/javascript/packs/components/home/index.vue.ts(13,20)
TS2307: Cannot find module '../shared/layout'.
Why can I no longer find the layout file when typescript is enabled? 启用打字稿后为什么不能再找到布局文件?
I remember running into a similar problem for presentational components. 我记得在演示组件中遇到了类似的问题。 Try adding an empty export in
shared/layout
so typescript can pick it up: 尝试在
shared/layout
添加一个空的导出,以便打字稿可以提取它:
<script lang="ts">
export default {}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.