runtime error when updating from 5.1.1 to 5.2.2
I updated my monorepo with this commit: https://github.com/IsaacScript/isaacscript/commit/b727ffa75fca93023e839900c42c46d973343f9d
Here is the corresponding CI run: https://github.com/IsaacScript/isaacscript/actions/runs/8392460435/job/22985155348
Knip throws the following runtime error:
Analyzing workspace ....
node:internal/modules/cjs/loader:1144
const err = new Error(message);
^
Error: Cannot find module 'D:/Repositories/isaacscript/configs/base-eslint'
Require stack:
- D:\Repositories\isaacscript\index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
at Function.resolve (node:internal/modules/helpers:187:19)
at Function._resolve [as resolve] (D:\Repositories\isaacscript\node_modules\jiti\dist\jiti.js:1:251148)
at resolve (file:///D:/Repositories/isaacscript/node_modules/knip/dist/util/require.js:13:48)
at getDependenciesDeep (file:///D:/Repositories/isaacscript/node_modules/knip/dist/plugins/eslint/helpers.js:28:50)
at getDependenciesDeep (file:///D:/Repositories/isaacscript/node_modules/knip/dist/plugins/eslint/helpers.js:31:34)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.resolveConfig (file:///D:/Repositories/isaacscript/node_modules/knip/dist/plugins/eslint/index.js:12:26)
at async WorkspaceWorker.findDependenciesByPlugins (file:///D:/Repositories/isaacscript/node_modules/knip/dist/WorkspaceWorker.js:202:54)
at async main (file:///D:/Repositories/isaacscript/node_modules/knip/dist/index.js:146:108) {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'D:\\Repositories\\isaacscript\\index.js' ]
}
I believe this is a regression, since the run-time error did not occur in version 5.1.1.
Unfortunately from the error message alone I can't deduct the problem. Please create a minimal reproduction of the issue so I can look into it.
Here's a small repository with a minimal reproduction: https://github.com/peplin/knip-issue570-repro
This issues seems to be related to running dependency resolution on the nested .eslintrc.js file. That extends an .eslintrc.js from the top of the workspace, which extends from the root. When knip runs dependency resolution, it seems to be looking for an .eslintrc.js in an intermediate directory where there is none.
I removed the offending .eslintrc.js file to confirm this is the problem, and the error does go away. However, it appears in another (non-eslint) file that uses a relative import, so I think there's a general issue with how dependencies are being resolved in newer versions of knip.
:rocket: This issue has been resolved in v5.12.1. See Release 5.12.1 for release notes.
Using Knip in a commercial project? Please consider sponsoring me.
Thanks @peplin, super helpful! Just what we needed.
Thanks! I can confirm this is fixed for us in 5.12.1.