常见的一些报错问题合集

问题 1、 node 版本不兼容

@achrinza/node-ipc@9.2.2: The engine “node” is incompatible with this module. Expected version “8 || 10 || 12 || 14 || 16 || 17”. Got “20.15.0” 报错为例

  1. 去 npmjs.com 查看该依赖对应的 node 版本要求
  2. 找到后在 package.json 中添加如下代码
1
2
3
"resolutions": {
"@achrinza/node-ipc": "9.2.9"
},

问题 2、webpack 打包时验证 node_modules 代码

1
2
3
4
5
6
## vue.config.js
transpileDependencies: [/node_modules/],

## tsconfig.json
"exclude": ["node_modules"]

问题 3、fs 模块报错

1
2
3
4
5
6
7
8
9
10
## vue.config.js

parallel: false,
configureWebpack: {
resolve: {
fallback: {
fs: false,
},
}
}

问题 4、xlsx-style 报错 jszip is not a constructor

1
2
3
4
5
6
在node_modules处找到node_modules\xlsx-style\xlsx.js 文件。

if(typeof jszip === 'undefined') jszip = require('./js'+'zip').JSZip;(应该在xlsx.js文件1339行左右)
替换成
if(typeof jszip === 'undefined') jszip = require('./jszip.js');

问题 5、vue-router 同路由跳转报错

1
2
3
4
5
import VueRouter from "vue-router";
const routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (location) {
return routerPush.call(this, location).catch((error) => error);
};