Ann*_*nna 8 node-modules eslint vue.js yarnpkg vue-cli
为自定义规则创建新的 eslint-plugin 后,vue-cli-service build失败(eslint按预期工作,由 触发时./node_modules/.bin/eslint --ext .js,.vue,.json ./ --max-warnings=0)。
从工作环境开始vue-cli-service build,按照https://blog.webiny.com/create-custom-eslint-rules-in-2-minutes-e3d41cb6a9a0 上的简化说明,也会重现该问题。vue-cli-service build在每一步运行后,它在第 4 步之后开始失败yarn add --dev file:./eslint,并且在所有步骤完成后构建仍然失败。
错误信息:
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.
Run Code Online (Sandbox Code Playgroud)
vue-cli-service build运行后仍然失败yarn install,表示它已经是最新的。
这个特定TypeError: eslint.CLIEngine is not a constructor错误的大多数结果都声称用户应该升级他们的 JetBrains IDE。但是,我vue-cli-service build在命令行上运行而不是使用 JetBrains。
错误消息引用的代码是(带有前面的上下文):
MYPATH/node_modules/@vue/cli-plugin-eslint/node_modules/eslint-loader/index.js
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.
Run Code Online (Sandbox Code Playgroud)
编辑:我在下面@DelenaMalan 的建议下@vue/cli-plugin-eslint通过编辑 yarn's将版本从 3.11.0升级到 4.1.2 package.json。构建仍然失败并出现错误:
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.
Run Code Online (Sandbox Code Playgroud)
编辑 2:按照@CGundlach 的建议,我删除并重新安装了此处链接的 repro上的节点模块,但我仍然遇到eslint.CLIEngine is not a constructor错误
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] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning "@vue/eslint-config-airbnb > eslint-import-resolver-webpack@0.11.1" has unmet peer dependency "webpack@>=1.11.0".
[4/4] 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.
Run Code Online (Sandbox Code Playgroud)
确保在运行npm ci、npm i或 时解决所有警告yarn install。对我来说,全新安装后出现以下警告:
$ vue-cli-service build\n\n\xe2\xa0\xa7 Building for production...\n\n ERROR Failed to compile with 1 error 20:47:55\n\nSyntax Error: Thread Loader (Worker 0)\neslint.CLIEngine is not a constructor\n\n\nYou may use special comments to disable some warnings.\nUse // eslint-disable-next-line to ignore the next line.\nUse /* eslint-disable */ to ignore all warnings in a file.\nRun Code Online (Sandbox Code Playgroud)\n当我进行全新安装并通过降低eslint版本解决对等依赖问题时,一切都按预期进行。
因此,请尝试将您的eslint依赖项降级到正确的版本。对我来说,我必须降级到eslint< 7.0.0。
npm i -D eslint@6.8.0\n# or yarn\nyarn add -D eslint@6.8.0\nRun Code Online (Sandbox Code Playgroud)\n