简体   繁体   English

无法导入模块为打字稿

[英]Can't import modules is typescript

I have a folder structure like this: 我有这样的文件夹结构:

src\
   components\
     Home\
       index.tsx
   redux\
     reducer.ts
   index.tsx

In ./index.tsx ./index.tsx

in have 在有

export const App = <p> Hello World </p>

When i try to import { App } from ../index.tsx in reducer.js is say App is undefined 当我尝试import { App } from ../index.tsx reducer.js import { App } from ../index.tsxApp is undefined

But if i import Home from '../components/Home' it works well. 但是,如果我import Home from '../components/Home'则效果很好。

What could be the issue? 可能是什么问题?

import { App } from ../index ? import { App } from ../index You should import js rather than jsx . 您应该导入js而不是jsx Which is, I suppose, compiled and stored next to your .jsx files. 我想是将其编译并存储在您的.jsx文件旁边。 You can also update your webpack config in order to import jsx directly, not sure it's an option in this case. 您也可以更新webpack配置以直接导入jsx,在这种情况下不确定是否可以选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM