【问题标题】:Can't find /bundle.js.map on the server Node.js在服务器 Node.js 上找不到 /bundle.js.map
【发布时间】:2020-09-24 00:25:44
【问题描述】:

我正在学习教程,现在当我尝试更新用户数据时出现此错误,我尝试重新安装包裹包

npm install -g bundle-js

这里是 package.json:

这是目录:

由于我的 bundle.js 和 bundle.js.map 在 /public/js 下,我如何路由目录

【问题讨论】:

    标签: node.js parceljs


    【解决方案1】:

    您可以从official documentation 运行npm install -g parcel-bundler

    在 package.json 里面添加--out-dir .public/js 像这样:

    "scripts": {
        "watch:js": "parcel watch ./public/js/index.js --out-dir ./public/js --out-file bundle.js",
        "build:js": "parcel build ./public/js/index.js --out-dir ./public/js --out-file bundle.js"
      },
    

    编辑:重新启动 Node.js 服务器和捆绑器以使更改生效。

    【讨论】:

      【解决方案2】:

      package.json “脚本”:{ "watch:js": "包裹监视 ./public/js/index.js --out-dir ./public/js --out-file bundle.js", "build:js": "parcel build ./public/js/index.js --out-dir ./public/js --out-file bundle.js" },

      我遇到了同样的问题。这是我在控制台中收到的消息: DevTools 无法加载 SourceMap:无法加载 http://127.0.0.1:8000/bundle.js.map 的内容:HTTP 错误:状态代码 404,net::ERR_HTTP_RESPONSE_CODE_FAILURE

      一切似乎都正常,文件的位置在 .public/js 中,服务器无缘无故地在根目录中寻找文件。

      【讨论】:

        【解决方案3】:

        好吧,一旦 bundler.js 编译完成,如果我们打开它并滚动到最底部,就会有一行:

        //# sourceMappingURL=/bundle.js.map
        

        我们可以手动输入正确的路径,比如

        //# sourceMappingURL=/js/bundle.js.map
        

        错误会消失,但问题是为什么包裹会这样走……

        附言>

        终于找到了解决办法!您应该插入 --public-url 。 它会成功!

            "watch:js": "parcel watch ./public/js/index.js --out-dir ./public/js --out-file bundle.js --public-url .",
            "build:js": "parcel build ./public/js/index.js --out-dir ./public/js --out-file bundle.js --public-url ."
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-04-14
          • 1970-01-01
          • 1970-01-01
          • 2016-04-28
          • 2011-05-29
          • 2014-10-15
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多