JavaScript模块没有加载

发布于 2025-02-09 02:09:20 字数 879 浏览 0 评论 0原文

我正在尝试将一个模块导入我的JavaScript代码,该模块稍后应在WordPress服务器上运行。 目前,我想在Localhost上进行测试,但它给了我一个错误: “ http://127.0.0.1:46513/js/main.js”的SKRIPT已加载,尽管它是Mime-Typ(“ Text/html”)在Javascript中无效 这很奇怪,因为它是JS代码,而不是HTML。 我的主要.js看起来像这样:

const {origan,星座} = require('./ coundular-natal-horoscope-js/dist/dist/index.js');

and code> and index.html像这样:

<html>
  <head> Horoscope </head>
    <body>
        <script type="text/javascript" src="js/require.js"></script>
        <script type="text/javascript" src="js/main.js"></script>    
    </body>
</html>

我还尝试了不同的导入语法: import {Origin,星座}来自'/circular-natal-horoscope-js/dist/index.js'; 这给了我同样的错误。

唯一有效的是,当我将node main.js输入控制台时,origin和星座函数正在加载。

我如何在不使用控制台的情况下使用它在JS文件中工作?

I am trying to import a module to my JavaScript code, which should later run on a WordPress server.
Currently i wanted to test it on localhost, but it gives me an error like:
The Skript from "http://127.0.0.1:46513/js/main.js" was loaded, despite it's MIME-Typ ("text/html") is not valid in JavaScript
Which is strange because it is js code and not html.
My main.js looks like this:

const { Origin, Horoscope } = require('./circular-natal-horoscope-js/dist/index.js');

And index.html like this:

<html>
  <head> Horoscope </head>
    <body>
        <script type="text/javascript" src="js/require.js"></script>
        <script type="text/javascript" src="js/main.js"></script>    
    </body>
</html>

I also tried different import syntax:
import { Origin, Horoscope } from '/circular-natal-horoscope-js/dist/index.js';
Which gives me the same error.

The only thing which is working is, when i type in node main.js into console, then the Origin and Horoscope functions are beeing loaded.

How can i use this to be working in my js-files without using the console?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文