最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - TypeScript failed to compile - Badly attached item found - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 10

I 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)

发布评论

评论列表(0)

  1. 暂无评论