You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:运行Angular CLI的ng-serve命令时提示Cannot find module 'ejs'

Fixing "Cannot find module 'ejs'" When Running ng serve in Angular CLI

Hey there, sorry you're stuck with this frustrating error—let's get your Angular app up and running again. Here are the most common fixes to try, ordered from simplest to more thorough:

1. Install EJS Locally to Your Project

The error usually means your project is missing the ejs dependency, which might be required by some part of your build setup or a plugin. Run this command in your project root:

npm install ejs --save-dev

Adding --save-dev ensures it's marked as a development dependency, which is where it belongs for build-related tools.

2. Try Global EJS Installation (If Local Install Fails)

Occasionally, the global Angular CLI instance might rely on ejs being installed globally. Give this a shot:

npm install -g ejs

3. Clear NPM Cache and Reinstall Dependencies

Corrupted npm cache can cause module resolution issues. First clear the cache:

npm cache clean --force

Then reinstall all your project dependencies:

npm install

4. Wipe and Rebuild Your Dependency Folder

If the above steps don't work, your node_modules folder or lock file might be corrupted. Here's how to reset:

  • On macOS/Linux:
    rm -rf node_modules package-lock.json
    npm install
    
  • On Windows (Command Prompt):
    rmdir /s /q node_modules
    del package-lock.json
    npm install
    
  • If using Yarn:
    rm -rf node_modules yarn.lock
    yarn install
    

5. Update Angular CLI to the Latest Stable Version

Outdated CLI versions can have compatibility issues with newer dependencies. Update both global and local CLI instances:

# Update global CLI
npm install -g @angular/cli@latest

# Update local project CLI
npm install @angular/cli@latest --save-dev

After trying these steps, run ng serve again—this should resolve the missing ejs module error. If you're still having trouble, double-check if any custom webpack configurations or third-party plugins in your project are explicitly requiring ejs and ensure they're set up correctly.

内容的提问来源于stack exchange,提问作者Olufemi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:58:04