问题描述:
使用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
重新构建,显示成功!