node.jsvitestmodulenotfounderroryarn-workspacesyarnpkg-v4

Cannot find module /vitest/dist/chunks from /vitest/dist/worker.js when migrate to yarn v4 and to vitest


I use yarn workspases and one of workspaces threw this error:

file:///home/username/Projects/projectName/node_modules/tinypool/dist/chunk-E2J7JLFN.js:46
    throw error;
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/username/Projects/projectName/be-shared/node_modules/vitest/dist/chunks/index.lVXYBqEP.js' imported from /home/username/Projects/projectName/be-shared/node_modules/vitest/dist/worker.js
    at finalizeResolution (node:internal/modules/esm/resolve:265:11)
    at moduleResolve (node:internal/modules/esm/resolve:933:10)
    at defaultResolve (node:internal/modules/esm/resolve:1169:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:227:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:87:39)
    at link (node:internal/modules/esm/module_job:86:36) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///home/username/Projects/projectName/be-shared/node_modules/vitest/dist/chunks/index.lVXYBqEP.js'
}

Node.js v20.16.0
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

Solution

  • I've

    1. Deleted the /home/username/Projects/projectName/be-shared/node_modules/vitest directory
    2. Did yarn install in the /home/username/Projects/projectName directory

    P.S

    I think this answer may help not only with the vitest problem, but also with other packages with similar problem so I created this question. In that case, you will need to remove the package that you have not found. In my case, it's a vitest