暂无
Vant Cli 版本4.0.1
描述一下你遇到的问题。在 Vant Cli 里引入 Vant 后,需要配置 vite-plugin-style-import 来处理按需引入的样式问题,但是引入了之后,终端报了以下错误
Pre-bundling dependencies: 17:35:12
vue
@vant/touch-emulator
vue-router
@docsearch/js
(this will be run only when your dependencies or config have changed) 17:35:12
17:35:12
vite v2.8.6 dev server running at:
> Local: http://localhost:3000/ 17:35:12
> Network: http://10.98.165.39:3000/ 17:35:12
下午5:35:14 [vite] new dependencies found: vite-plugin-style-import, updating... 17:35:14
WARN 下午5:35:14 [vite] Failed to load source map for /@fs/Users/ronneyhuang/Wesure/H5/组件库/webapp-biz-component/node_modules/.pnpm/@vant+cli@4.0.1_sass@1.49.9+vue@3.2.31/node_modules/@vant/cli/node_modules/.vite/chunk-RSJERJUL.js?v=e104f1e1.
WARN 下午5:35:14 [vite] Failed to load source map for /@fs/Users/ronneyhuang/Wesure/H5/组件库/webapp-biz-component/node_modules/.pnpm/@vant+cli@4.0.1_sass@1.49.9+vue@3.2.31/node_modules/@vant/cli/node_modules/.vite/chunk-5FBSPP2L.js?v=e104f1e1.
✘ [ERROR] No matching export in "browser-external:path" for import "extname"
node_modules/.pnpm/@rollup+pluginutils@4.2.0/node_modules/@rollup/pluginutils/dist/es/index.js:1:9:
1 │ import { extname, win32, posix, isAbsolute, resolve } from 'path';
╵ ~~~~~~~
✘ [ERROR] No matching export in "browser-external:path" for import "win32"
node_modules/.pnpm/@rollup+pluginutils@4.2.0/node_modules/@rollup/pluginutils/dist/es/index.js:1:18:
1 │ import { extname, win32, posix, isAbsolute, resolve } from 'path';
╵ ~~~~~
✘ [ERROR] No matching export in "browser-external:path" for import "posix"
node_modules/.pnpm/@rollup+pluginutils@4.2.0/node_modules/@rollup/pluginutils/dist/es/index.js:1:25:
1 │ import { extname, win32, posix, isAbsolute, resolve } from 'path';
╵ ~~~~~
✘ [ERROR] No matching export in "browser-external:path" for import "isAbsolute"
node_modules/.pnpm/@rollup+pluginutils@4.2.0/node_modules/@rollup/pluginutils/dist/es/index.js:1:32:
1 │ import { extname, win32, posix, isAbsolute, resolve } from 'path';
╵ ~~~~~~~~~~
✘ [ERROR] No matching export in "browser-external:path" for import "resolve"
node_modules/.pnpm/@rollup+pluginutils@4.2.0/node_modules/@rollup/pluginutils/dist/es/index.js:1:44:
1 │ import { extname, win32, posix, isAbsolute, resolve } from 'path';
╵ ~~~~~~~
✘ [ERROR] No matching export in "browser-external:module" for import "createRequire"
node_modules/.pnpm/vite-plugin-style-import@2.0.0/node_modules/vite-plugin-style-import/dist/index.mjs:9:9:
9 │ import { createRequire } from 'module';
╵ ~~~~~~~~~~~~~
ERROR 下午5:35:15 [vite] error while updating dependencies: 17:35:15
Error: Build failed with 6 errors:
node_modules/.pnpm/@rollup+pluginutils@4.2.0/node_modules/@rollup/pluginutils/dist/es/index.js:1:9: ERROR: No matching export in "browser-external:path" for import "extname"
node_modules/.pnpm/@rollup+pluginutils@4.2.0/node_modules/@rollup/pluginutils/dist/es/index.js:1:18: ERROR: No matching export in "browser-external:path" for import "win32"
node_modules/.pnpm/@rollup+pluginutils@4.2.0/node_modules/@rollup/pluginutils/dist/es/index.js:1:25: ERROR: No matching export in "browser-external:path" for import "posix"
node_modules/.pnpm/@rollup+pluginutils@4.2.0/node_modules/@rollup/pluginutils/dist/es/index.js:1:32: ERROR: No matching export in "browser-external:path" for import "isAbsolute"
node_modules/.pnpm/@rollup+pluginutils@4.2.0/node_modules/@rollup/pluginutils/dist/es/index.js:1:44: ERROR: No matching export in "browser-external:path" for import "resolve"
重现步骤
-
vant.config.mjs 导入 vite-plugin-style-import
import { createStyleImportPlugin, VantResolve } from 'vite-plugin-style-import'
-
修改 configureVite
configureVite(config) { const { BUILD_TARGET } = process.env if (BUILD_TARGET === 'site') { config.plugins.splice( 4, 0, createStyleImportPlugin({ resolves: [VantResolve()], }) ) } return config }
-
运行本地开发服务器
pnpm run dev