admin管理员组文章数量:1307055
I'm having an issue with React & TypeScript where a ponent loads for a brief second, then immediately fails with the error:
[internal] TypeScript error in [internal] (undefined,undefined): badly attached item found. TSINTERNAL_ERROR
The affected code:
App.tsx:
import React, {useState, useMemo} from "react";
import MainMenu from "./MainMenu";
import Lobby from "./Lobby";
interface appComponentsInterface {
[key: string]: React.FC
}
const APP_COMPONENTS: appComponentsInterface = {
"MainMenu": MainMenu,
"Lobby": Lobby
}
export default () => {
const [appState, setAppState] = useState("MainMenu");
const AppComponent = useMemo(() => APP_COMPONENTS[appState], [appState]);
return (
<AppComponent />
)
}
MainMenu.tsx:
import React from "react";
const MainMenu : React.FC = () => {
return (
<div> MainMenu </div>
)
}
export default MainMenu;
Any advice would be appreciated - The error itself isn't too helpful.
I'm having an issue with React & TypeScript where a ponent loads for a brief second, then immediately fails with the error:
[internal] TypeScript error in [internal] (undefined,undefined): badly attached item found. TSINTERNAL_ERROR
The affected code:
App.tsx:
import React, {useState, useMemo} from "react";
import MainMenu from "./MainMenu";
import Lobby from "./Lobby";
interface appComponentsInterface {
[key: string]: React.FC
}
const APP_COMPONENTS: appComponentsInterface = {
"MainMenu": MainMenu,
"Lobby": Lobby
}
export default () => {
const [appState, setAppState] = useState("MainMenu");
const AppComponent = useMemo(() => APP_COMPONENTS[appState], [appState]);
return (
<AppComponent />
)
}
MainMenu.tsx:
import React from "react";
const MainMenu : React.FC = () => {
return (
<div> MainMenu </div>
)
}
export default MainMenu;
Any advice would be appreciated - The error itself isn't too helpful.
Share Improve this question asked May 21, 2020 at 17:33 user13380302user13380302 3- Try removing node_modules, lock files and reinstall. Make sure to use only yarn or npm, not both. – Phix Commented May 21, 2020 at 17:47
- @Phix Thank you, that worked perfectly. – user13380302 Commented May 21, 2020 at 18:03
- 1 just rebuilding the app was enough for me – Andy Commented Jul 28, 2020 at 10:12
1 Answer
Reset to default 10I have faced the same issue.
You probably installed nom modules and did not restart the dev server.
After installing any packages, try to restart the server(npm/yarn start)
本文标签: javascriptTypeScript failed to compileBadly attached item foundStack Overflow
版权声明:本文标题:javascript - TypeScript failed to compile - Badly attached item found - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741829500a2399847.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论