config.json(TypeError:仅支持绝对URL)

时间:2020-09-13 08:43:55

标签: javascript node.js

我的index.js中有这段代码

const config = require('./config.json');

而我的config.json的内容是

{
  "default_prefix": "?"
  }

但是我收到一个错误:TypeError:仅支持绝对URL。是什么导致错误?

如果我必须显示更多代码,只需在评论中问我

1 个答案:

答案 0 :(得分:0)

./ config.json是一个相对URL,它要求一个绝对URL。

尝试将其转换为绝对URL:https://stackoverflow.com/a/38829194/2875073

<div id="animation1_wrapper">
  <button id="button-ani">Toggle Animation Play State</button>
  <svg id="animation1" width="100%" height="100%" viewBox="0 0 418 255" fill="none" xmlns="http://www.w3.org/2000/svg">

    <g id="ani_graphic">
      <path class="animation1" d="M263.46 25.3801C257.63 29.2001 252.88 33.7801 249.33 37.8001H263.46V25.3801Z" fill="#000"></path>
      <path class="animation1" d="M301.26 37.8001V18.8701C300.92 18.7801 300.58 18.6801 300.24 18.6001C287.1 15.3201 275.8 18.2901 266.73 23.3901V37.8001H301.26Z" fill="#f1f1f1"></path>
      <path class="animation1" d="M329.15 37.8001C324.38 30.2101 316.5 23.6801 304.54 19.8201V37.8001H329.15Z" fill="#f1f1f1"></path>
      ----
      ----
    </g>
  </svg>
</div>

或者您可以在此处尝试其他方法来读取json文件:Using Node.JS, how do I read a JSON file into (server) memory?