Why does 'vue-cli-service build' fail after creating a new eslint-plugin, with error 'TypeError: eslint.CLIEngine is not a constructor'?

huangapple go评论89阅读模式
英文:

Why does 'vue-cli-service build' fail after creating a new eslint-plugin, with error 'TypeError: eslint.CLIEngine is not a constructor'?

问题

It seems like you're facing an issue with the eslint.CLIEngine not being recognized as a constructor. This error might be related to your project's configuration or dependencies. To resolve this issue, you can try the following steps:

  1. Ensure that you have the latest version of Node.js and Yarn installed.

  2. Delete the node_modules directory and the yarn.lock file in your project folder:

    rm -rf node_modules
    rm yarn.lock
    
  3. After deleting these files, run yarn install again to reinstall the project dependencies:

    yarn install
    
  4. If the issue persists, consider upgrading or downgrading the versions of eslint and related packages in your package.json file to ensure compatibility.

  5. Check your ESLint configuration to ensure it's correctly set up, and there are no conflicts with other ESLint configurations.

  6. Verify that you're using the correct ESLint commands when running linting tasks in your project.

  7. If none of the above steps resolve the issue, you might want to check if there are any specific project-related configurations or custom ESLint rules causing conflicts.

These steps should help you troubleshoot and resolve the eslint.CLIEngine is not a constructor error in your project.

英文:

After creating a new eslint-plugin for a custom rule, vue-cli-service build fails (eslint works as expected, when triggered by ./node_modules/.bin/eslint --ext .js,.vue,.json ./ --max-warnings=0).

GitHub repository reproducing issue

Starting in an environment with a working vue-cli-service build, following the simplified instructions at <https://blog.webiny.com/create-custom-eslint-rules-in-2-minutes-e3d41cb6a9a0>, also reproduces the issue. Running vue-cli-service build after every step, it starts failing after step 4: yarn add --dev file:./eslint, and the build still fails after all the steps are completed.

Error message:

ERROR  Failed to compile with 32 errors      

Module build failed (from ./node_modules/@vue/cli-plugin-eslint/node_modules/eslint-loader/index.js):
TypeError: eslint.CLIEngine is not a constructor
   at Object.module.exports (MYPATH/node_modules/@vue/cli-plugin-eslint/node_modules/eslint-loader/index.js:223:27)

***repeats 31 more times***

You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.
ERROR  Build failed with errors.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

vue-cli-service build stills fails after running yarn install, which says it is already up to date.

Most results for this specific TypeError: eslint.CLIEngine is not a constructor error claim the user should upgrade their JetBrains IDE. However, I am running vue-cli-service build on the command line and not using JetBrains.

The code referred to by the error message is (with preceding context):

MYPATH/node_modules/@vue/cli-plugin-eslint/node_modules/eslint-loader/index.js

...
var config = assign(
    // loader defaults
    {
      cacheIdentifier: JSON.stringify({
        &quot;eslint-loader&quot;: pkg.version,
        eslint: eslintVersion || &quot;unknown version&quot;
      }),
      eslintPath: &quot;eslint&quot;
    },
    userOptions
  );

  if (typeof config.formatter === &quot;string&quot;) {
    try {
      config.formatter = require(config.formatter);
      if (
        config.formatter &amp;&amp;
        typeof config.formatter !== &quot;function&quot; &amp;&amp;
        typeof config.formatter.default === &quot;function&quot;
      ) {
        config.formatter = config.formatter.default;
      }
    } catch (_) {
      // ignored
    }
  }

  var cacheDirectory = config.cache;
  var cacheIdentifier = config.cacheIdentifier;

  delete config.cacheIdentifier;

  // Create the engine only once per config
  var configHash = objectHash(config);

  if (!engines[configHash]) {
    var eslint = require(config.eslintPath);
    engines[configHash] = new eslint.CLIEngine(config); //Error happens here
  }
...

Edit: I upgraded @vue/cli-plugin-eslint from version 3.11.0 to 4.1.2 by editing yarn's package.json, at the suggestion of @DelenaMalan below. The build still fails with error:

ERROR  Failed to compile with 1 errors                                                                                                            7:51:01 PM

Module build failed (from ./node_modules/@vue/cli-service/node_modules/thread-loader/dist/cjs.js):
Thread Loader (Worker 0)
eslint.CLIEngine is not a constructor
    at PoolWorker.fromErrorObj (MYPATH/node_modules/@vue/cli-service/node_modules/thread-loader/dist/WorkerPool.js:262:12)
    at MYPATH/node_modules/@vue/cli-service/node_modules/thread-loader/dist/WorkerPool.js:204:29
    at mapSeries (MYPATH/node_modules/neo-async/async.js:3625:14)
    at PoolWorker.onWorkerMessage (MYPATH/node_modules/@vue/cli-service/node_modules/thread-loader/dist/WorkerPool.js:170:35)
    at readBuffer (MYPATH/node_modules/@vue/cli-service/node_modules/thread-loader/dist/WorkerPool.js:152:14)
    at Object.module.exports (MYPATH/node_modules/@vue/cli-plugin-eslint/node_modules/eslint-loader/index.js:223:27)

You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.
 ERROR  Build failed with errors.
error Command failed with exit code 1.

Edit 2:
I deleted and reinstalled the node modules on the repro linked here, as recommended by @CGundlach, but I still have the eslint.CLIEngine is not a constructor error

Annas-MacBook-Pro:eslint-test-project anna$ rm -rf node_modules/
Annas-MacBook-Pro:eslint-test-project anna$ yarn install
yarn install v1.21.1
[1/4] &#128269;  Resolving packages...
[2/4] &#128666;  Fetching packages...
[3/4] &#128279;  Linking dependencies...
warning &quot;@vue/eslint-config-airbnb &gt; eslint-import-resolver-webpack@0.11.1&quot; has unmet peer dependency &quot;webpack@&gt;=1.11.0&quot;.
[4/4] &#128296;  Building fresh packages...
✨  Done in 14.14s.
Annas-MacBook-Pro:eslint-test-project anna$ yarn build
yarn run v1.21.1
$ vue-cli-service build

⠏  Building for production...

 ERROR  Failed to compile with 1 errors                                                                                                           12:28:32 PM

Module build failed (from ./node_modules/thread-loader/dist/cjs.js):
Thread Loader (Worker 0)
eslint.CLIEngine is not a constructor
    at PoolWorker.fromErrorObj (/Users/anna/projects/yarn-vue-eslint/eslint-test-project/node_modules/thread-loader/dist/WorkerPool.js:262:12)
    at /Users/anna/projects/yarn-vue-eslint/eslint-test-project/node_modules/thread-loader/dist/WorkerPool.js:204:29
    at mapSeries (/Users/anna/projects/yarn-vue-eslint/eslint-test-project/node_modules/neo-async/async.js:3625:14)
    at PoolWorker.onWorkerMessage (/Users/anna/projects/yarn-vue-eslint/eslint-test-project/node_modules/thread-loader/dist/WorkerPool.js:170:35)
    at readBuffer (/Users/anna/projects/yarn-vue-eslint/eslint-test-project/node_modules/thread-loader/dist/WorkerPool.js:152:14)
    at Object.module.exports (/Users/anna/projects/yarn-vue-eslint/eslint-test-project/node_modules/eslint-loader/index.js:223:27)

You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.
 ERROR  Build failed with errors.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

答案1

得分: 4

请确保在运行npm cinpm iyarn install时,解决所有警告。对我来说,在进行全新安装后,出现了以下警告:

$ vue-cli-service build

⠧  Building for production...

 ERROR  Failed to compile with 1 error                           20:47:55

Syntax Error: Thread Loader (Worker 0)
eslint.CLIEngine is not a constructor


您可以使用特殊注释来禁用某些警告。
使用// eslint-disable-next-line来忽略下一行。
使用/* eslint-disable */来忽略文件中的所有警告。

当我进行全新安装并通过降低我的eslint版本来解决对等依赖问题时,一切都按预期工作。

因此,尝试将您的eslint依赖项降级到正确的版本。对我来说,我不得不降级到eslint < 7.0.0。

npm i -D eslint@6.8.0
# 或者使用yarn
yarn add -D eslint@6.8.0
英文:

Make sure all warnings are resolved when you run either npm ci, npm i or yarn install. For me the following warnings were showed after doing a fresh install:

$ vue-cli-service build

⠧  Building for production...

 ERROR  Failed to compile with 1 error                           20:47:55

Syntax Error: Thread Loader (Worker 0)
eslint.CLIEngine is not a constructor


You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.

When I did a fresh install and resolved the peer dependency issue by decreasing my eslint version everything works as expected.

So try to downgrade your eslint dependency to the correct version. For me I had to downgrade to eslint < 7.0.0.

npm i -D eslint@6.8.0
# or yarn
yarn add -D eslint@6.8.0

huangapple
  • 本文由 发表于 2020年1月6日 23:02:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/59614362.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定