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

Angular 7项目执行ng serve报错,npm install无效求助

Hey Sarah, sorry to hear your Angular 7 project started throwing those weird type errors out of nowhere! Those TS2304 errors about missing ArrayBuffer and Object are almost always related to missing library configurations in your tsconfig.json file, not issues with your dependencies (which explains why reinstalling node_modules didn't help). Let's walk through the fixes step by step:

Fixing TS2304: Cannot find name 'ArrayBuffer'/'Object' in Angular 7

1. Check and Update Your tsconfig.json Lib Settings

The most common culprit here is that your TypeScript compiler isn't including the necessary standard library definitions to recognize global types like ArrayBuffer and Object.

Head to your project root's tsconfig.json file, look for the compilerOptions section, and make sure the lib array includes these entries:

{
  "compilerOptions": {
    // ... other existing options
    "lib": [
      "es2017",
      "dom",
      "es2015.core"
    ]
    // ... other existing options
  }
}
  • es2015.core covers basic JavaScript types like Object
  • es2017 includes definitions for ArrayBuffer and other ES2017 features
  • dom adds browser-specific type definitions that Angular relies on

If your lib array was missing any of these, adding them should resolve most of those type errors.

2. Clear Angular's Build Cache

Sometimes cached build artifacts can cause unexpected issues, even after reinstalling dependencies. Run these commands to clear the cache and restart your dev server:

# Delete the Angular cache folder
rm -rf node_modules/.cache
# Start the server with cache cleared
ng serve --clearCache

3. Verify TypeScript Version Compatibility

Looking at your package.json, you're using TypeScript 3.1.1 which is fully compatible with Angular 7.2.x (Angular 7 officially supports TypeScript 3.1.x). But just to be safe, you can re-install the exact TypeScript version to rule out any corruption:

npm install typescript@3.1.1 --save-dev

4. Double-Check for Custom Type Conflicts

If the above steps don't work, take a quick look at any custom *.d.ts files in your project. Rarely, custom type definitions can override or interfere with global TypeScript types. But since you already reinstalled node_modules, this is less likely.

Give these steps a try—most folks fix this issue with the first two steps alone. Let me know if you run into any snags!

内容的提问来源于stack exchange,提问作者Sarah De Cock

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 08:53:47