knip icon indicating copy to clipboard operation
knip copied to clipboard

runtime error when updating from 5.1.1 to 5.2.2

Open Zamiell opened this issue 1 year ago • 1 comments

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.

Zamiell avatar Mar 22 '24 15:03 Zamiell

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.

webpro avatar Mar 22 '24 16:03 webpro

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.

peplin avatar May 03 '24 16:05 peplin

: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.

webpro avatar May 03 '24 17:05 webpro

Thanks @peplin, super helpful! Just what we needed.

webpro avatar May 03 '24 17:05 webpro

Thanks! I can confirm this is fixed for us in 5.12.1.

peplin avatar May 03 '24 21:05 peplin