next.js AWS Amplify在deply上显示“无法找到模块”

yeotifhr  于 2023-04-05  发布在  其他
关注(0)|答案(1)|浏览(134)

我有Next.js + Typescript项目,在本地编译良好,但在部署到AWS Amplify时失败。我不明白为什么找不到此模块。
来自扩增状态的日志:

[WARNING]: Failed to compile.
./pages/index.tsx:3:17
                                    Type error: Cannot find module 'components/Tag' or its corresponding type declarations.
                                    [0m [90m 1 | [39m[36mimport[39m { [33mEntry[39m[33m,[39m getEntries } [36mfrom[39m [32m"lib/data"[39m[33m;[39m[0m
                                    [0m [90m 2 | [39m[36mimport[39m styles [36mfrom[39m [32m"./_index.module.css"[39m[33m;[39m[0m
                                    [0m[31m[1m>[22m[39m[90m 3 | [39m[36mimport[39m [33mTag[39m [36mfrom[39m [32m"components/Tag"[39m[33m;[39m[0m
                                    [0m [90m   | [39m                [31m[1m^[22m[39m[0m
                                    [0m [90m 4 | [39m[36mimport[39m [33mRef[39m [36mfrom[39m [32m"components/Ref"[39m[33m;[39m[0m
                                    [0m [90m 5 | [39m[0m
                                    [0m [90m 6 | [39m[36minterface[39m [33mHomeProps[39m {[0m

“index.tsx”组件正在导入Tag组件,如下所示:

import Tag from "components/Tag";

组件本身看起来像这样:

const Tag = ({ text, link }: TagProps) => <a className={styles.tag} href={ link }>{ text }</a>

export default Tag;

该文件是“index.tsx”,位于“Tag”文件夹中,该文件夹还包含“Tag.module.css”文件,因此从我在tsconfig.json中定义的基本URL到组件的完整路径是“components/Tag/index.tsx”,但以这种方式导入它也失败了。
下面是我的tsconfig.json:

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

这是我的包。json:

{
  "name": "",
  "description": "",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build && next export",
    "watch": "next-remote-watch ./posts",
    "clean": "rm -rf .next out"
  },
  "dependencies": {
    "gray-matter": "^4.0.3",
    "markdown-it": "^12.3.2",
    "next": "^13.2.4",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "remark": "^14.0.2",
    "remark-html": "^15.0.2",
    "remark-prism": "^1.3.6"
  },
  "devDependencies": {
    "@types/node": "^18.15.11",
    "@types/react": "^18.0.31",
    "next-remote-watch": "^2.0.0",
    "typescript": "^5.0.3"
  }
}

所以,“npm run build”在本地工作,但是当Amplify运行“npm run build”时,它找不到组件。为什么?

798qvoo8

798qvoo81#

原来我已经把我的父文件夹的大小写从“tag”改为“Tag”了,但是git没有接收到这个变化。

git config core.ignorecase false

然后提交并推送更改。

相关问题