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

启动Node.js应用时出现Error: Cannot find module 'compression'错误求助

解决 "Cannot find module 'compression'" 错误

Error: Cannot find module 'compression'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object. (.....\node_modules\webpack-dev-server\lib\Server.js:11:18)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tr...

Hey there! This error pops up because the compression module — which webpack-dev-server relies on for its functionality — isn’t installed in your project’s dependencies. Here’s how to fix it step by step:

  • First, install the missing module
    Navigate to your project’s root directory in the terminal, then run one of these commands based on your package manager:

    • For npm: npm install compression --save-dev
    • For Yarn: yarn add compression --dev
  • If the error persists after installation
    Sometimes cached dependencies can cause issues. Try these steps:

    1. Delete your node_modules folder and lock file:
      • On macOS/Linux: rm -rf node_modules package-lock.json
      • On Windows Command Prompt: rmdir /s /q node_modules && del package-lock.json
      • On Windows PowerShell: Remove-Item -Recurse -Force node_modules; Remove-Item package-lock.json
    2. Reinstall all dependencies: npm install (or yarn install)
  • Optional: Specify a compatible version
    If you’re using an older version of webpack-dev-server, it might require a specific version of compression. You can install a known-compatible version like this:
    npm install compression@^1.7.4 --save-dev

Once you’ve done this, try starting your application again — it should work without the module not found error!

内容的提问来源于stack exchange,提问作者David Slabý

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 08:03:41