electron / forge

:electron: A complete tool for building and publishing Electron applications
https://electronforge.io
MIT License
6.46k stars 514 forks source link

After packaging, eslint cannot find the 'vue espint parser' module #3395

Closed jsmgg closed 12 months ago

jsmgg commented 12 months ago

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:

Failed to load parser 'vue-eslint-parser' declared in 'CLIOptions': Cannot find module 'vue-eslint-parser'\nRequire stack:\n- /__placeholder__.js

The configuration code for eslint is as follows:

const cli = new ESLint({
      overrideConfig:{
        env: ["browser","node","es6","amd","mocha","jest"].reduce((res, k)=>{
          res[k] = true;
          return res;
        },{}),
        ignorePatterns: ignore,
        parser: 'vue-eslint-parser',
        parserOptions:{
          parser:"@typescript-eslint/parser",
          ecmaVersion: 2020,
          extraFileExtensions: ['.vue'],
          tsconfigRootDir: `${absoluteDir}`,
          sourceType:"module",
          ecmaFeatures: {
            jsx: true
          }
        },
        plugins:[
          'sonarjs'
        ],
      },
      useEslintrc: false,
      extensions:[".vue",".js",".ts",".jsx","tsx"],
      baseConfig:{
        rules:{
          complexity: [2, { max: 0 }],
          'sonarjs/cognitive-complexity':[2, 0],
          'vue-template-complex':1
        }
      },
      fix: false,
      rulePaths:[pathObj.join(__filename,`../../rules`)]
    });
    const report = await cli.lintFiles(absoluteDir);

eslint Code connection

Steps to reproduce

//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

jsmgg commented 12 months ago

Solved the issue with the eslint module loader