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

nextjs 运行报错

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

    我使用单一仓库的方式创建的项目,然后现在分别有 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  
       302 天前
    看一眼 `tsconfig.json` 里有没有把你要编译的 ts 包含进去
    xiaoweipeng
        2
    xiaoweipeng  
    OP
       302 天前
    @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  
       302 天前
    你的 model 是不是在 node_modules 里?
    PTLin
        4
    PTLin  
       302 天前
    你这不如直接 type TypeEnum = 'folder'|'file'得了,反正你用非数字创建 enum 的实例本身就是错误用法。
    xiaoweipeng
        5
    xiaoweipeng  
    OP
       302 天前
    @NessajCN 是的,是 pnpm 安装的
    xiaoweipeng
        6
    xiaoweipeng  
    OP
       302 天前
    @PTLin 还有这种说法吗,我 ts 新手
    sjn9588
        7
    sjn9588  
       302 天前
    NessajCN
        8
    NessajCN  
       302 天前
    @xiaoweipeng 所以肯定报错呀,你的 tsconfig 里都把 node_modules 给 exclude 了。正常在 node_modules 里的都是编译成 js 了再放进去的。
    Leviathann
        10
    Leviathann  
       302 天前
    @PTLin enum 本身就是错误的,没有正确用法一说
    xiaoweipeng
        11
    xiaoweipeng  
    OP
       302 天前
    @sjn9588 是这样的,感谢!!!
    xiaoweipeng
        12
    xiaoweipeng  
    OP
       302 天前
    @NessajCN 不能直接用 ts 是吧,了解,感谢
    PTLin
        13
    PTLin  
       302 天前   ❤️ 1
    @sjn9588 我没说明白,我说的是 let xxx:EnumType = "xxx"这种操作
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2910 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 14:15 · PVG 22:15 · LAX 07:15 · JFK 10:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.