node.jsangularnpm

How to fix Angular Error: Cannot find module './compile.js'


A few days ago, I installed Angular 20 (global) and tried working on a new project. For the new project i installed the latest LTS node version (22.17.0). Today i went back to an important old one and tried to continue working on it. It is currently written in Angular 18. I tried to build it, but it failed. I tried many things to get it to work again. After one hour I removed npm, nodejs, angular from my computer and I reinstalled Node 20.19.3 (npm 10.8.2) and Angular 18.2.13.

I created a new angular test project to check if it works: no ssr, with scss named test.

It still failed with the same error (when executing ng serve):

An unhandled exception occurred: Cannot find module './compile.js'
Require stack:
 - D:\work\test\node_modules\css-select\lib\index.js
 - D:\work\test\node_modules\critters\dist\critters.js
 - D:\work\test\node_modules\@angular\build\src\utils\index-file\inline-critical-css.js
 - D:\work\test\node_modules\@angular\build\src\utils\index-file\index-html-generator.js
 - D:\work\test\node_modules\@angular\build\src\tools\esbuild\index-html-generator.js
 - D:\work\test\node_modules\@angular\build\src\builders\application\execute-post-bundle.js
 - D:\work\test\node_modules\@angular\build\src\builders\application\execute-build.js
 - D:\work\test\node_modules\@angular\build\src\builders\application\index.js
 - D:\work\test\node_modules\@angular\build\src\private.js
 - D:\work\test\node_modules\@angular-devkit\build-angular\src\builders\dev-server\builder.js
 - D:\work\test\node_modules\@angular-devkit\build-angular\src\builders\dev-server\index.js
 - D:\work\test\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js

What can I try now? Thank you in advance!


Solution

  • The issue was created by an update of the css-select package roughly 6 hours ago. See the corresponding pull request and linked issues there for more information. The updated npm package 5.2.2 landed like 1 hour ago, and fixes the issue. So just update your packages.