//Nodejs: v16.14.0
const {ESLint} = require('eslint');// version: 8.45.0
const path = require("path");
function scan(dir){
try{
const cli = new ESLint({
overrideConfig:{
env: ["browser","node","es6","amd","mocha","jest"].reduce((res, k)=>{
res[k] = true;
return res;
},{}),
ignorePatterns: [],
parser: 'vue-eslint-parser',
parserOptions:{
parser:"@typescript-eslint/parser", // version: 9.3.1
ecmaVersion: 2020,
extraFileExtensions: ['.vue'],
tsconfigRootDir: `${absoluteDir}`,
sourceType:"module",
ecmaFeatures: {
jsx: true
}
}
},
useEslintrc: false,
extensions:[".vue",".js",".ts",".jsx","tsx"],
baseConfig:{
rules:{
complexity: [2, { max: 0 }]
}
},
fix: false
});
const report = await cli.lintFiles(absoluteDir);
return report;
}catch(e){
/*
The development environment can run normally. After packaging, the error message here is as follows:
Failed to load parser 'vue-eslint-parser' declared in 'CLIOptions': Cannot find module 'vue-eslint-parser'\nRequire stack:\n- /__placeholder__.js
*/
console.log(e.message);
return [];
}
}
Additional information
Called in my program eslint@8.52.0 The API scans the file code using the following pass: vue-eslint-parser@9.3.1.
The development environment can run normally. After packaging, the error message here is as follows:
Failed to load parser 'vue-eslint-parser' declared in 'CLIOptions': Cannot find module 'vue-eslint-parser'\nRequire stack:\n- /placeholder.js
Pre-flight checklist
Electron Forge version
6.4.2
Electron version
27.0.2
Operating system
macOS 12.4
Last known working Electron Forge version
6.4.2
Expected behavior
Normal call to eslint API to scan code
Actual behavior
The development environment can be called normally, and an error message is reported after packaging. The error message is as follows:
The configuration code for eslint is as follows:
eslint Code connection
Steps to reproduce
Additional information
Called in my program eslint@8.52.0 The API scans the file code using the following pass: vue-eslint-parser@9.3.1. The development environment can run normally. After packaging, the error message here is as follows: Failed to load parser 'vue-eslint-parser' declared in 'CLIOptions': Cannot find module 'vue-eslint-parser'\nRequire stack:\n- /placeholder.js