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

如何在项目未本地安装Angular的情况下启动Angular应用?

Fixing the "@angular/core" Dependency Error When Running Your Project

Hey there! Since you're coming from a React background and new to all things Angular, let's break down what's going on here and get your project up and running.

First, Let's Pinpoint the Root Issue

That error "You seem to not be depending on "@angular/core". This is an error." pops up because of a key mismatch:

  • You're using ng serve, which is a command exclusively for modern Angular (2+) projects managed by the Angular CLI.
  • But your project only has a single angular.js file—this is almost certainly an AngularJS (Angular 1.x) project, a completely separate framework from the modern Angular you installed via CLI. Angular CLI commands don't work with AngularJS projects at all.

How to Run Your AngularJS Project

AngularJS doesn't rely on the Angular CLI, so here are two simple ways to launch it:

  • Option 1: Use a static file server (most reliable)
    1. If you don't have a static server installed, run npm install -g serve (you already have Node.js set up since you used Angular CLI, so this will work smoothly).
    2. Navigate to your project's root folder (where angular.js and index.html live) in your terminal.
    3. Run serve—this will spin up a server, typically at http://localhost:3000. Open that URL in your browser, and your project should load right up.
  • Option 2: Open directly in your browser (if no cross-origin issues)
    Just double-click your index.html file to open it in a browser. Note: This might fail if your project loads external resources or uses AJAX, since browsers block some requests from local files.

If It Is Supposed to Be a Modern Angular Project

If the coding test explicitly states this is a modern Angular (2+) project (unlikely given the single angular.js file), here's how to fix the dependency gap:

  1. Navigate to the project root in your terminal.
  2. Run npm install—this will install all required local dependencies (including @angular/core) from the project's package.json file.
  3. Once installation finishes, run ng serve again, and it should work as expected.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 08:28:24