【Vue】webpack polyfilling 报错

1. 出现问题描述

npm run serve 项目时报错

ERROR Failed to compile with 1 error 10:33:22 ├F10: AM┤

error in ./src/router/routes.js

Module not found: Error: Can't resolve 'path' in '/Users/guolijun/Desktop/vue-oil-enterprise/src/router'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.

This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:

  • add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'

  • install 'path-browserify'

If you don't want to include a polyfill, you can use an empty module like this:

resolve.fallback: { "path": false }

2. 解决方案

搜索到解决方案: https://www.reddit.com/r/react/comments/w7yddk/how_do_i_fix_this_error_with_webpack_polyfilling/
package.json添加

javascript 复制代码
"browser": {

"path": false

}
相关推荐
明月_清风7 分钟前
Meta 开源了一个 AI Native 组件库:Astryx,150+ React 组件,专为 AI Agent 而设计
前端·人工智能·ai编程
仨孩子的爹19 分钟前
Lodop、hiprint 与 vue-print-designer:打印控件选型对比
vue.js
用户8508692761528 分钟前
秒杀系统中 Shell 脚本并发控制 Bug:究竟哪里出了
前端
炫酷的大高个3 小时前
6 亿播放的闪身步,我用前端算出 15 倍重心差
前端·javascript
不可能片场3 小时前
内容运营自动化 配图折行别把词切两半
前端·electron
Lank_M3 小时前
HEIC转JPG统一转sRGB,P3高饱和色就回不来了
前端
补码缩写3 小时前
sharp默认转JPG颜色没错,ICC和EXIF却全没了
前端
用户7783366132113 小时前
SerpBase AI Overview 引用卡片:React 组件实战
前端
林小帅3 小时前
【笔记】Prisma v7 + SQLite TS2305 及连锁 TS7006 问题
前端·javascript·后端
ruanno_top3 小时前
四个 canvas 组件,在 2 倍屏上一直是糊的
vue.js