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

MacOS环境IPFS Demo执行npm run dev报错:缺失dev脚本求助

解决npm run dev报错:missing scripts dev的问题

Hey Elias, let's work through this issue step by step! You're absolutely right that the root cause here is the missing dev script in your project's package.json—npm can only run commands that are explicitly defined in the scripts section of that file, so it's throwing an error because it can't find what you're asking for.

针对你的项目结构的具体解决方案

Looking at the file structure you shared (with app, index.html, and truffle.js), this looks like an older Truffle-based project, which typically doesn't use npm run dev to launch the frontend. Here are a few fixes to try:

  • Try Truffle's built-in server
    Old Truffle projects often use truffle serve instead of custom npm scripts. Run this command from your project root directory (that's contracts-master, not the contracts subfolder) — it will start a local server (usually on port 8080), automatically inject your contract ABIs into the frontend, and serve up your index.html file directly.

  • Use a static file server
    If truffle serve doesn't work, you can use a simple static server to host your frontend:

    1. Install http-server globally first: npm install -g http-server
    2. Navigate to your project root directory (contracts-master)
    3. Run http-server
    4. Open your browser and visit the URL it outputs (usually http://localhost:8080)
  • Check the Readme.md first!
    You mentioned there's a Readme.md in the root folder—this is the most reliable source for project-specific instructions. It almost certainly lists the correct commands to launch the demo, so don't skip this step!

额外排查建议

  • Double-check your working directory
    Make sure you're running commands from the contracts-master root folder, not the contracts subdirectory. npm looks for package.json in the current working directory, so if you're in contracts, it won't find the right configuration.
  • Look at your package.json scripts
    Open the root package.json file and check the scripts section. If there's a start, serve, or build command listed, try running npm run [command-name] instead.
  • Check for build steps
    If your project uses a bundler like Webpack or Parcel, you might need to run npm run build first to compile the frontend assets, then serve the generated files.

学习资源建议

  • Get familiar with the Truffle workflow for older project versions (your truffle.js file indicates it's an older setup—newer Truffle projects use truffle-config.js). Focus on documentation matching your project's Truffle version to avoid confusion.
  • When learning to combine IPFS with Ethereum, start with official, up-to-date demos or Truffle Boxes—these will have consistent, well-documented setup steps that avoid version compatibility issues.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 03:32:57