首页 前端知识 使用pnpm run build:dev时,报错:error during build: Error: [vite]: Rollup failed to resolve import “sortabl

使用pnpm run build:dev时,报错:error during build: Error: [vite]: Rollup failed to resolve import “sortabl

2024-08-25 23:08:44 前端知识 前端哥 87 820 我要收藏

问题描述:

使用pnpm run build:dev进行打包时,出现bug提示:


E:\working\project_name>pnpm run build:dev

> yudao-ui-admin-vue3@2.0.0-snapshot build:dev E:\working\project_name
> node --max_old_space_size=8192 ./node_modules/vite/bin/vite.js build --mode local-dev
Building [██████████████████████████░░░░░░░░░░░░░░] 65% | Time: 143.1s
Build failed. Please check the error message

Building [██████████████████████████░░░░░░░░░░░░░░] 65% | Time: 163.2serror during build:
Error: [vite]: Rollup failed to resolve import "sortablejs" from "E:/working/project_name/src/views/mall/product/spu/form/ActivityOrdersSort.vue?vue&type=script&setup=true&
lang.ts".
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`
    at viteWarn (file:///E:/working/project_name/node_modules/.pnpm/vite@4.5.0_@types+node@20.11.20_sass@1.71.1_terser@5.28.1/node_modules/vite/dist/node/chunks/dep-bb8a833
9.js:48216:27)
    at onRollupWarning (file:///E:/working/project_name/node_modules/.pnpm/vite@4.5.0_@types+node@20.11.20_sass@1.71.1_terser@5.28.1/node_modules/vite/dist/node/chunks/dep-
bb8a8339.js:48248:9)
    at onwarn (file:///E:/working/project_name/node_modules/.pnpm/vite@4.5.0_@types+node@20.11.20_sass@1.71.1_terser@5.28.1/node_modules/vite/dist/node/chunks/dep-bb8a8339.
js:47976:13)
    at file:///E:/working/project_name/node_modules/.pnpm/rollup@3.29.4/node_modules/rollup/dist/es/shared/node-entry.js:24276:13
    at Object.logger [as onLog] (file:///E:/working/project_name/node_modules/.pnpm/rollup@3.29.4/node_modules/rollup/dist/es/shared/node-entry.js:25950:9)
    at ModuleLoader.handleInvalidResolvedId (file:///E:/working/project_name/node_modules/.pnpm/rollup@3.29.4/node_modules/rollup/dist/es/shared/node-entry.js:24862:26)
    at file:///E:/working/project_name/node_modules/.pnpm/rollup@3.29.4/node_modules/rollup/dist/es/shared/node-entry.js:24822:26
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
 ELIFECYCLE  Command failed with exit code 1.

在这里插入图片描述


原因分析:

Rollup 在build构建过程中无法解析 sortablejs 模块的导入的路径。这个bug的产生可能会在运行时破坏应用程序。所以想显式地外部化这个模块,需要把它添加到导入到提示需要导入的路径。


解决方案:

检查对应路径中,是否存在sortablejs 包,如果不存在,则安装依赖。如果存在,可以检查导入路径是否正确。

pnpm install sortablejs

(https://img-blog.csdnimg.cn/direct/b305f9ac2e1249549e1731b4e7cbf9da.png)
重新构建,显示成功!在这里插入图片描述

转载请注明出处或者链接地址:https://www.qianduange.cn//article/16905.html
标签
bug
评论
发布的文章

LoopBack组件JSONAPI使用指南

2024-09-04 23:09:43

编译JSONCPP源码

2024-09-04 23:09:49

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!