V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yazoox
V2EX  ›  程序员

兄弟姐妹们,这个 codesandbox 项目,你们本地能够跑起来么?

  •  
  •   yazoox · 142 天前 · 473 次点击
    这是一个创建于 142 天前的主题,其中的信息可能已经有所发展或是发生改变。

    https://codesandbox.io/p/sandbox/5rb54

    codesandbox 在线,能够正常编译,跑起来。但是,当我把代码下载到本地, yarn start后,却出错。这是为什么呢?这个 Demo.tsx 文件,就在那里啊......

    另,我自己 clone 了一个 https://codesandbox.io/p/sandbox/mui-v4-treeview-react-dnd-forked-g3t6v3

    也是这样,在线可以跑,下载代码到本地,就会出错,和上面的错误一样.

    我在 macOS 和 windows 两套系统下,都试过了,报错一样

    Compiled with problems:
    ×
    ERROR
    Cannot find module './Demo'
        at webpackMissingModule ( http://localhost:3000/static/js/bundle.js:15:50)
        at ./src/index.tsx ( http://localhost:3000/static/js/bundle.js:15:131)
        at options.factory ( http://localhost:3000/static/js/bundle.js:40763:31)
        at __webpack_require__ ( http://localhost:3000/static/js/bundle.js:40208:33)
        at http://localhost:3000/static/js/bundle.js:41340:37
        at http://localhost:3000/static/js/bundle.js:41342:12
    
    whj768702
        1
    whj768702  
       142 天前
    index.tsx 文件中的引入加上文件类型吧。
    import Demo from "./Demo.tsx";
    AJian
        2
    AJian  
       142 天前
    看了下这个仓库用的是`react-scripts`,看`react-scripts`源代码得知,当工程根目录没有`tsconfig.json`文件时,webpack 的`resolve.extensions`中的含`ts`的后缀会被移除,所以不能自动补全 tsx 后缀。

    可以在 src/index.tsx 中的第 3 行"./Demo"加上.tsx 后缀,改成"./Demo.tsx"应该就可以正常了,或者加上`tsconfig.json`文件,并安装好相关的 types 包
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2776 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 10:13 · PVG 18:13 · LAX 03:13 · JFK 06:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.