运行以下命令
在最新的 node16,npm8 环境"stylelint": "stylelint --allow-empty-input 'src/**/*.{css,less,scss,sass}'","stylelint:fix": "npm run stylelint -- --fix",执行 npm run stylelint:fix 时报错,Error: Could not find "@applint/stylelint-config". Do you need a `configBasedir`?复现案例 https://github.com/cloudyan/lint-example/runs/6643983274?check_suite_focus=true
跟踪一下在源码这里
// stylelint/lib/augmentConfig.jsasync function augmentConfigFull(stylelint, filePath, cosmiconfigResult) {if (!cosmiconfigResult) {return null;}const config = cosmiconfigResult.config;const filepath = cosmiconfigResult.filepath;const configDir = stylelint._options.configBasedir || path.dirname(filepath || '');
是个依赖问题,改为使用 yarn 好了
将 @applint/stylelint-config 安装到项目目录,能解决此问题,但这不是个好解决方案将依赖安装改为 yarn 或 pnpm 时,没问题了yarn: https://github.com/cloudyan/lint-example/runs/6644161656?check_suite_focus=truepnpm: https://github.com/cloudyan/lint-example/runs/6644486967?check_suite_focus=true又折腾了几遍,npm 竟然也好了npm: https://github.com/cloudyan/lint-example/runs/6644411799?check_suite_focus=true对比了下,主要是这个 @applint/stylelint-config 包安装的目录路径有区别,对比 package-lock.json 能看到区别。一个在@applint/spec 目录下,一个安装到项目根目录下了。前者就会报错。但为什么会出现这种问题?非常奇怪
