nextjs 13组件内部文件夹的jsconfig.json自定义路径在Vercel上引发错误

mrfwxfqh  于 2023-06-29  发布在  其他
关注(0)|答案(1)|浏览(156)

我使用Next.js作为:

version 13.4.4
eslint: on
app directory: yes
server components: yes
js or ts: js

在我的jsconfig.json我已经设置了一个路径快捷方式为我的components文件夹是位于/src

{
  "compilerOptions": {
    "paths": {
      "@/components/*": ["./src/components/*"]
    }
  }
}

这对于直接到**/components**的文件很有效,如:

import Hero from '@/components/Hero'

但是我创建了一个子文件夹**/components/sections/,在sections里面我有一个组件Hello.js**,我在我的主页上导入为:

import Hello from '@/components/sections/Hello'

这与我之前在Next.js 12上使用的过程相同,但在Vercel上部署版本13.4.4时,部署失败并出现错误:
未找到模块:无法解析“@/components/sections/Hello”
为什么?

z6psavjg

z6psavjg1#

复制-粘贴此代码到tsconfig.json

{
  "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"
      }
    ],
    "baseUrl": ".",
    "paths": {
      "@components/*": ["./components/*"],
      "@assets/*": ["./assets/*"],
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}

相关问题