doutuo7156 2017-11-13 09:55 采纳率: 100%
浏览 43
已采纳

找不到捆绑的文件

I am using Golang (Echo) for my backend and React for my frontend. When I bundle my code using webpack, the file is created; however, I am getting an error in my console when I go to localhost:3000 stating the bundle file cannot be found. This is the exact error message: GET http://localhost:3000/build/app.bundle.js net::ERR_ABORTED.

Here is my server:

func main() {
    env.SetEnvVars()

    e := echo.New()
    e.File("/", "server/static/index.html")

    e.Logger.Fatal(e.Start(os.Getenv("PORT")))
}

Here is my webpack.config.js file:

module.exports = {
  entry: './client/main.jsx',
  output: {
    path: path.resolve(__dirname, 'server/static/build'),
    filename: 'app.bundle.js'
  },
  ...

And the script tag in my index.html file is:

<script src="./build/app.bundle.js"></script>

The directory path regarding these files is currently:

/
  server/
    main.go
    static/
      index.html
      build/
        app.bundle.js

Any help would be appreciated!

  • 写回答

1条回答 默认 最新

  • dongxie8906 2017-11-13 10:36
    关注

    The echo server you've set up only serves one single path, the root path ("/"), by rendering the contents of the index.html file. Because you haven't set up any other handlers for that server, any request to a path other than the root will result in 404, including those requests made from the index page via script and link tags, e.g.; <script src="./build/app.bundle.js"></script>.

    To be able to serve a request to a path like "/static/build/app.bundle.js" for example you need to tell the server how to do that by registering a new handler.

    With the echo server you can use its Static method to do that.

    e.Static("/static", "static")
    

    Please keep in mind that the links you use in html tags, the location of the corresponding files on your machine, and the location from where you launched your app matters if you use relative paths like ./build/app.bundle.js, and because of that the two arguments to e.Static may need to be somewhat different from the example here.

    Here's a bit more info.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器