首页 > 解决方案 > vercel 部署无法需要`.d.ts`文件

问题描述

我的 next.js 应用程序可以在我的机器上运行,但是当部署在 Vercel 上时,它在构建时失败并出现以下错误:

Error! Unable to require `.d.ts` file.
This is usually the result of a faulty configuration or import. Make sure there is a `.js`, `.json` or another executable extension and loader (attached before `ts-node`) available alongside `emotion.d.ts`.

它似乎无法在我的类型文件夹中检测到 Emotion.d.ts。它像 /src/types/emotion.d.ts 一样位于 src 中,所以我尝试更改我的设置以包含如下内容。

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve"
  },
  "include": [
    "next-env.d.ts",
    "src/**/*"
  ],
  "exclude": [
    "node_modules"
  ]
}

尽管如此,还是没有运气。

我的emotion.d.ts 文件只是简单地声明了一个这样的类型。

import '@emotion/react';

declare module '@emotion/react' {
  export interface Theme {
    color: {
      primary0: string;
      primary1: string;
      primary2: string;
      primary3: string;
      primary4: string;
      primary5: string;
      primary6: string;
      primary7: string;
      secondary0: string;
      secondary1: string;
      secondary2: string;
      secondary3: string;
      secondary4: string;
      secondary5: string;
      secondary6: string;
      tertiary0: string;
      tertiary1: string;
      tertiary2: string;
      text0: string;
      text1: string;
      text2: string;
      text3: string;
      text4: string;
      bg0: string;
      bg1: string;
      bg2: string;
    };
    size: {
      maxWidth: string;
    };
    mediaQuery: {
      sp: string;
      pc: string;
    };
  }
}

任何帮助将不胜感激。谢谢!

标签: typescriptnext.jsvercel

解决方案


推荐阅读