nextjs 运行报错

332 天前
 xiaoweipeng

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

1486 次点击
所在节点    React
13 条回复
NessajCN
332 天前
看一眼 `tsconfig.json` 里有没有把你要编译的 ts 包含进去
xiaoweipeng
332 天前
@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
332 天前
你的 model 是不是在 node_modules 里?
PTLin
332 天前
你这不如直接 type TypeEnum = 'folder'|'file'得了,反正你用非数字创建 enum 的实例本身就是错误用法。
xiaoweipeng
332 天前
@NessajCN 是的,是 pnpm 安装的
xiaoweipeng
332 天前
@PTLin 还有这种说法吗,我 ts 新手
sjn9588
332 天前
NessajCN
332 天前
@xiaoweipeng 所以肯定报错呀,你的 tsconfig 里都把 node_modules 给 exclude 了。正常在 node_modules 里的都是编译成 js 了再放进去的。
sjn9588
332 天前
Leviathann
332 天前
@PTLin enum 本身就是错误的,没有正确用法一说
xiaoweipeng
332 天前
@sjn9588 是这样的,感谢!!!
xiaoweipeng
332 天前
@NessajCN 不能直接用 ts 是吧,了解,感谢
PTLin
332 天前
@sjn9588 我没说明白,我说的是 let xxx:EnumType = "xxx"这种操作

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/944821

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX