Ubuntu下执行npm init @eslint/config安装ES Lint因缺package.json报错求助
解决ESLint初始化报错:缺少package.json文件
问题场景
在Ubuntu 20.08系统中,使用Node 18.13.0、npm 8.19.3环境,执行npm init @eslint/config安装ESLint时触发报错,错误明确提示需先创建package.json文件才能继续。
解决方案
- 先在当前工作目录执行
npm init(若想快速生成默认配置,可加-y参数:npm init -y),按提示完成package.json文件的创建。 - 重新执行
npm init @eslint/config,即可正常完成ESLint的初始化配置。
错误原因
ESLint的初始化流程需要依托package.json来管理后续的依赖安装、配置关联等操作,因此必须确保当前目录存在该文件才能执行初始化。
完整错误日志
Error: A package.json file is necessary to initialize ESLint. Run `npm init` to create a package.json file and try again. at promptUser (file:///home/syedfaheem/.npm/_npx/7ef27be80482e586/node_modules/@eslint/create-config/lib/init/config-initializer.js:370:15) at initializeConfig (file:///home/syedfaheem/.npm/_npx/7ef27be80482e586/node_modules/@eslint/create-config/lib/init/config-initializer.js:586:12) at file:///home/syedfaheem/.npm/_npx/7ef27be80482e586/node_modules/@eslint/create-config/bin/create-config.js:10:1 at ModuleJob.run (node:internal/modules/esm/module_job:194:25) Node.js v18.13.0 npm ERR! code 1 npm ERR! path /home/syedfaheem npm ERR! command failed npm ERR! command sh -c -- create-config npm ERR! A complete log of this run can be found in: npm ERR! /home/syedfaheem/.npm/_logs/2023-02-27T05_48_54_008Z-debug-0.log
内容的提问来源于stack exchange,提问作者Syed Faheem
相关产品推荐
相关产品推荐

