nextjs 运行报错 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xiaoweipeng
V2EX    React

nextjs 运行报错

  •  
  •   xiaoweipeng 2023-06-01 10:28:18 +08:00 2302 次点击
    这是一个创建于 932 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我使用单一仓库的方式创建的项目,然后现在分别有 website 和 model ,现在我在 website 中引入了 model ,pnpm -F @icelf/website add @icelf/model, 当我引入 model 中的类实例化时,提示 Module parse failed: The keyword 'enum' is reserved, 但是我把类定义到同一个项目下时却不会出现问题,求大佬解答,感谢! p9x5Bin.png p9x5szV.png p9x56MT.png p9x5bLD.png

    13 条回复    2023-06-01 12:15:29 +08:00
    NessajCN
        1
    NessajCN  
       2023-06-01 10:50:04 +08:00
    看一眼 `tsconfig.json` 里有没有把你要编译的 ts 包含进去
    xiaoweipeng
        2
    xiaoweipeng  
    OP
       2023-06-01 11:04:51 +08:00
    @NessajCN website 的吗 {
    "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
    {
    "name": "next"
    }
    ],
    "paths": {
    "@/*": ["./src/*"]
    }
    },
    "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
    "exclude": ["node_modules"]
    }
    NessajCN
        3
    NessajCN  
       2023-06-01 11:10:06 +08:00
    你的 model 是不是在 node_modules 里?
    PTLin
        4
    PTLin  
       2023-06-01 11:13:18 +08:00
    你这不如直接 type TypeEnum = 'folder'|'file'得了,反正你用非数字创建 enum 的实例本身就是错误用法。
    xiaoweipeng
        5
    xiaoweipeng  
    OP
       2023-06-01 11:16:45 +08:00
    @NessajCN 是的,是 pnpm 安装的
    xiaoweipeng
        6
    xiaoweipeng  
    OP
       2023-06-01 11:17:16 +08:00
    @PTLin 还有这种说法吗,我 ts 新手
    sjn9588
        7
    sjn9588  
       2023-06-01 11:18:15 +08:00
    NessajCN
        8
    NessajCN  
       2023-06-01 11:18:30 +08:00
    @xiaoweipeng 所以肯定报错呀,你的 tsconfig 里都把 node_modules 给 exclude 了。正常在 node_modules 里的都是编译成 js 了再放进去的。
    sjn9588
        9
    sjn9588  
       2023-06-01 11:20:13 +08:00
    Leviathann
        10
    Leviathann  
       2023-06-01 11:21:26 +08:00
    @PTLin enum 本身就是错误的,没有正确用法一说
    xiaoweipeng
        11
    xiaoweipeng  
    OP
       2023-06-01 11:29:41 +08:00
    @sjn9588 是这样的,感谢!!!
    xiaoweipeng
        12
    xiaoweipeng  
    OP
       2023-06-01 11:30:23 +08:00
    @NessajCN 不能直接用 ts 是吧,了解,感谢
    PTLin
        13
    PTLin  
       2023-06-01 12:15:29 +08:00   1
    @sjn9588 我没说明白,我说的是 let xxx:EnumType = "xxx"这种操作
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2656 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 24ms UTC 11:53 PVG 19:53 LAX 03:53 JFK 06:53
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86