xiaoweipeng
V2EX  ›  React

nextjs 运行报错

  •  
  •   xiaoweipeng · Jun 1, 2023 · 3042 views
    This topic created in 1259 days ago, the information mentioned may be changed or developed.

    我使用单一仓库的方式创建的项目,然后现在分别有 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 replies  •  2023-06-01 12:15:29 +08:00
    NessajCN
    NessajCN
    Jun 1, 2023
    1
    看一眼 `tsconfig.json` 里有没有把你要编译的 ts 包含进去
    xiaoweipeng
    xiaoweipeng
    OP
    Jun 1, 2023
    2
    @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
    NessajCN
    Jun 1, 2023
    3
    你的 model 是不是在 node_modules 里?
    PTLin
    PTLin
    Jun 1, 2023
    4
    你这不如直接 type TypeEnum = 'folder'|'file'得了,反正你用非数字创建 enum 的实例本身就是错误用法。
    xiaoweipeng
    xiaoweipeng
    OP
    Jun 1, 2023
    5
    @NessajCN 是的,是 pnpm 安装的
    xiaoweipeng
    xiaoweipeng
    OP
    Jun 1, 2023
    6
    @PTLin 还有这种说法吗,我 ts 新手
    NessajCN
    NessajCN
    Jun 1, 2023
    8
    @xiaoweipeng 所以肯定报错呀,你的 tsconfig 里都把 node_modules 给 exclude 了。正常在 node_modules 里的都是编译成 js 了再放进去的。
    Leviathann
    Leviathann
    Jun 1, 2023
    10
    @PTLin enum 本身就是错误的,没有正确用法一说
    xiaoweipeng
    xiaoweipeng
    OP
    Jun 1, 2023
    11
    @sjn9588 是这样的,感谢!!!
    xiaoweipeng
    xiaoweipeng
    OP
    Jun 1, 2023
    12
    @NessajCN 不能直接用 ts 是吧,了解,感谢
    PTLin
    PTLin
    Jun 1, 2023❤️1
    13
    @sjn9588 我没说明白,我说的是 let xxx:EnumType = "xxx"这种操作
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2256 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 209ms · UTC 13:59 · PVG 21:59 · LAX 05:59 · JFK 08:59
    ♥ Do have faith in what you're doing.