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

使用astronomy-bundle-js库时的JavaScript导入错误求助

解决 astronomy-bundle-js 模块导入错误的方案

核心修复:修改导入语句

直接替换你andtest.js中的导入代码为:

import { createTimeOfInterest } from './astronomy-bundle/time/createTimeOfInterest.js';

错误原因解析

  1. MIME类型不匹配错误
    最初的import {createTimeOfInterest} from "./astronomy-bundle/time/";指向目录而非具体文件,WAMP服务器默认返回该目录的HTML索引页面(MIME类型为text/html),但浏览器需要加载的是JavaScript模块(application/javascript),因此触发拦截。

  2. 导出导入不匹配错误
    你尝试的默认导入import createTimeOfInterest from './...'语法不匹配库的导出方式——createTimeOfInterest.js使用的是命名导出(即export { createTimeOfInterest }),必须用花括号包裹的命名导入语法才能正确匹配。

可选优化

如果astronomy-bundle根目录下存在index.js或类似入口文件,可直接从入口导入,写法更简洁:

import { createTimeOfInterest } from './astronomy-bundle/index.js';

服务器配置兜底检查

若仍有MIME类型相关问题,可在项目根目录创建.htaccess文件,添加以下内容强制服务器识别JS文件的正确MIME类型:

AddType application/javascript .js

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 14:22:44