DevsDawn
DevsDawn

修复date-fns-tz导入失败问题

在执行yarn build打包node项目时,出现以下错误:

[vite]: Rollup failed to resolve import "date-fns/_lib/cloneObject/index.js" from "node_modules/date-fns-tz/esm/formatInTimeZone/index.js".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
error during build:
Error: [vite]: Rollup failed to resolve import "date-fns/_lib/cloneObject/index.js" from "node_modules/date-fns-tz/esm/formatInTimeZone/index.js".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

原因是本地缓存不完整或出现错误,无法找到对应的依赖文件,打开该文件后,发现文件内容只有正常文件的一部分,怀疑是使用的npm镜像没有完整文件内容。可通过运行以下命令重建本地缓存,重新尝试打包即可成功:

yarn cache clean
若无特别说明,本文采用 CC BY-SA 4.0 协议进行许可。如需转载,请附上本文链接和本声明。
本文链接:https://devsdawn.com/2022/09/soloving-date-fns-tz-import-failed/
DigitalOcean云服务,NYSE上市公司,注册即送200USD体验金
Vultr云服务,全球25+地域,注册即送100USD体验金

发表回复

textsms
account_circle
email

DevsDawn

修复date-fns-tz导入失败问题
在执行yarn build打包node项目时,出现以下错误: [vite]: Rollup failed to resolve import "date-fns/_lib/cloneObject/index.js" from "node_modules/date-fns-tz/esm/formatInTimeZo…
扫描二维码继续阅读
2022-09-23