javascript - 错误 : Uncaught ReferenceError: module is not defined when using module. 导出

标签 javascript html module.exports

完整错误: 未捕获的 ReferenceError:模块未定义在 vsop87Bearth.js:1

我正在尝试使用我从这个 ( https://github.com/commenthol/astronomia ) 存储库中找到的一些 js 文件来计算太阳的直 Angular 坐标。我是 js 和服务器的新手,所以我不确定如何使用 module.exports。 有一个名为 vsop87Bearth.js 的文件,其中包含一些模拟地球的坐标,它看起来像这样:

module.exports = {
  stuff: numbers,
  name: "earth"
};

我需要使用 vsop87Bearth.js 文件和一个名为 position() 的函数来执行我需要的操作。这是模块 Funcion_PSol.js 我在其中尝试计算事物:

import position from './astronomia-master/src/solarxyz.js'
import Planet from './astronomia-master/src/planetposition.js'
import * as earth from './astronomia-master/data/vsop87Bearth.js' //I'm not sure of THIS line
var tierra = new Planet(earth);
var pos = position(earth, 2448908.5)

另外,这个错误也可能是HTML文件引起的,就是这个:

<!DOCTYPE html>
<html>
<head>
    <script type="module" src="./astronomia-master/data/vsop87Bearth.js"></script>
    <script type="module" src="Funcion_PSol.js"></script>
</head>
</html>

注意:我使用 browsersync 来托管我的项目,我没有使用 Node

最佳答案

由于您使用的是 esm 语法,因此需要将导出语法更新为以下内容。


export = {
  stuff: numbers,
  name: "earth"
};

https://nodejs.org/api/esm.html#esm_json_modules

关于javascript - 错误 : Uncaught ReferenceError: module is not defined when using module. 导出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61788313/

相关文章:

javascript 和测试数字

javascript - 使用 jquery ajax json 发送表单数据

javascript - Jquery - 在输入时,使用跨度类获取 td 内的跨度值

javascript - iPad 音频自动播放

javascript - 如何在 Nodejs 中正确从父目录导出和 require ?

javascript - 根据字符串数组更改 li 元素的颜色

javascript - 从 JavaScript 中的单个节点创建节点列表

html - 相对 Div 元素未注册到绝对定位的子元素

javascript - 有没有办法从 JavaScript 文件中获取所有导出的名称?

node.js - 如何向 module.exports 路由中的长格式返回请求添加参数?