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

React项目执行npm run build报错:index.js源文件路径错误

Fixing "Module not found: Can't resolve '/demo/src/index.js'" in React + nwb Build

Hey there, let's break down this build error you're hitting. The key line in your error log tells us exactly what's going wrong:

Module not found: Error: Can't resolve '/Users/david/git/demoapp/demo/src/index.js' in '/Users/david/git/demoapp'

Webpack (which nwb uses under the hood) can't locate your demo app's entry file. Here are the most common fixes to try:

  • Double-check the file path and existence
    Head over to /Users/david/git/demoapp/demo/src/ in your file system and make sure:

    1. The src folder actually exists inside the demo directory
    2. There's an index.js file in that folder (watch out for typos or capitalization issues—like Index.js instead of index.js, since some environments are case-sensitive)
  • Verify your nwb configuration
    If you have a custom nwb.config.js file in your project root, open it and check the demo entry configuration. It should point to the correct path of your index.js. For reference, the default nwb setup expects:

    module.exports = {
      demo: {
        entry: './demo/src/index.js'
      }
    }
    

    If this path was modified incorrectly, that's definitely causing the issue.

  • Clean build caches and retry
    Sometimes stale cache files can cause weird path resolution issues. Run these commands to clear things up:

    nwb clean
    npm run build
    

    If that doesn't work, you can also delete the node_modules/.cache folder manually before rebuilding.

  • Confirm your project structure matches nwb's expectations
    Nwb has standard project structures for React apps. A typical setup for a demo should look like this:

    demoapp/
    ├── demo/
    │   └── src/
    │       └── index.js
    ├── node_modules/
    └── package.json
    

    If your files are arranged differently, you'll need to either adjust your directory structure to match this or update the entry path in your nwb config.

Give these steps a try—most of the time, this error boils down to a missing file or a typo in the path.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 04:02:23