AWS 在 deply 上放大"Cannot find module"



我有Next.js + Typescript项目,在本地编译良好,但在部署到AWS Amplify时失败。我不明白为什么找不到这个模块。

来自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.module.css"因此,从我在tsconfig中定义的基url到组件的完整路径。json是"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"
]
}

这里是我的package.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运行"它找不到组件。为什么?

原来我把父文件夹的大小写从"tag";Tag"git并没有接受这个变化。固定:

git config core.ignorecase false

然后提交和推送更改。

相关内容

最新更新