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

处理googleapis模块缺失问题时,执行npm run build报错如何解决?

Fixing "missing script: build" + Original "Can't find module googleapis" Issue

Hey there, let's tackle this two-part problem step by step—first the immediate build script error, then your original module not found issue.

1. Resolve the "missing script: build" Error

The npm run build command relies on a script named build defined in your project's package.json file. Since you’re seeing this error, that script doesn’t exist yet. Here’s how to fix it:

  • Open your project’s root package.json file.
  • Look for the "scripts" section. If it doesn’t exist, create it. Add a build command tailored to your TypeScript project:
    "scripts": {
      "build": "tsc"
    }
    
    This tells npm to run the TypeScript compiler (tsc) when you execute npm run build.
  • Save the file, then re-run npm run build—the script error should be gone.

Pro tip: Instead of relying on a global TypeScript installation (which can cause version conflicts across projects), install TypeScript locally to your project:

npm install typescript --save-dev

Then update your build script to use the local compiler:

"scripts": {
  "build": "npx tsc"
}

2. Fix the Original "Can't find module googleapis" Issue

Now that the build script is sorted, let’s make sure the googleapis module is properly installed:

  • Install the googleapis package as a project dependency:
    npm install googleapis --save
    
  • If you’re using TypeScript, you’ll also need the type definitions for googleapis to avoid type errors:
    npm install @types/googleapis --save-dev
    
  • Finally, double-check that your node_modules directory exists (if not, run npm install to install all project dependencies) and that your import statement for googleapis is correct (e.g., import { google } from 'googleapis';).

Quick Troubleshooting Check

If you still run into issues:

  • Verify that your package.json is in the root directory of your project (where you’re running npm commands from).
  • Clear your npm cache with npm cache clean --force and re-install dependencies if needed.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 09:47:29