【问题标题】:Problem with CSS module not found when deploying to vercel部署到 Vercel 时找不到 CSS 模块的问题
【发布时间】:2023-03-25 11:25:01
【问题描述】:

这是错误日志。我无法终生解决这个问题。在开发中一切正常,但在部署时失败。 :(

23:12:53.687    Failed to compile.
23:12:53.687    ModuleNotFoundError: Module not found: Error: Can't resolve '../../styles/Homebody.module.css' in '/vercel/workpath0/components/Home'
23:12:53.687    > Build error occurred
23:12:53.688    Error: > Build failed because of webpack errors
23:12:53.688        at /vercel/workpath0/node_modules/next/dist/build/index.js:15:918
23:12:53.689        at runMicrotasks (<anonymous>)
23:12:53.689        at processTicksAndRejections (internal/process/task_queues.js:93:5)
23:12:53.689        at async /vercel/workpath0/node_modules/next/dist/build/tracer.js:3:470
23:12:53.704    npm ERR! code ELIFECYCLE
23:12:53.704    npm ERR! errno 1
23:12:53.707    npm ERR! next_front@0.1.0 build: `next build && next export`
23:12:53.707    npm ERR! Exit status 1
23:12:53.707    npm ERR! 
23:12:53.707    npm ERR! Failed at the next_front@0.1.0 build script.
23:12:53.707    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
23:12:53.714    npm ERR! A complete log of this run can be found in:
23:12:53.714    npm ERR!     /vercel/.npm/_logs/2021-02-24T23_12_53_708Z-debug.log
23:12:53.719    Error: Command "npm run build" exited with 1

【问题讨论】:

  • 你的 css 模块 styles/Homebody.module.css 的名称是否正确?如果是,请在 dev 上尝试 yarn build 看看输出是什么
  • 问题似乎出在文件路径上,记住你可以根据你的扩展使用jsconfig或tsconfig来定义根路径,因此你可以使用styles/
  • 都是大小写问题。 :)

标签: next.js vercel


【解决方案1】:

一件事是所有.module.css 文件都以大写字母开头。有时。但是,您仍然会收到相同的错误。更糟糕的是,对于不同的.module.css 文件,该错误不断发生。所以有时你会得到A.module.css not found,有时你会得到B.module.css not found。

然后我删除了node_modules 并运行了npm i。没有结果;同样的错误。

对我有用的是创建一个新项目:

yarn create next-app

...然后将旧模块中的所有文件一一添加,同时每次重新部署应用程序以检查它是否仍然有效。

这并不优雅,但它足够快并且可以解决问题。

【讨论】:

    猜你喜欢
    • 2022-01-13
    • 2022-01-25
    • 2023-01-31
    • 2022-10-07
    • 2023-03-10
    • 2021-04-22
    • 2020-10-04
    • 2018-03-17
    • 2023-01-15
    相关资源
    最近更新 更多