admin管理员组

文章数量:1393120

Complete error: Uncaught ReferenceError: module is not defined at vsop87Bearth.js:1

I`m trying to use some js files that I found from this() repository to calculate the rectangular coordinates of the sun. I'm new to js and servers so im not sure on how to use module.exports. There is a file called vsop87Bearth.js with some coordinates that modelates the earth and it looks like this:

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

And I need to use the vsop87Bearth.js file with a function called position() to do what I need. This is the module Funcion_PSol.js where Im trying to calculate things:

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)

Also, the error might be caused from the HTML file, this is it:

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

Note: I´m using browsersync to host my project and Im not using Node

Complete error: Uncaught ReferenceError: module is not defined at vsop87Bearth.js:1

I`m trying to use some js files that I found from this(https://github./menthol/astronomia) repository to calculate the rectangular coordinates of the sun. I'm new to js and servers so im not sure on how to use module.exports. There is a file called vsop87Bearth.js with some coordinates that modelates the earth and it looks like this:

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

And I need to use the vsop87Bearth.js file with a function called position() to do what I need. This is the module Funcion_PSol.js where Im trying to calculate things:

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)

Also, the error might be caused from the HTML file, this is it:

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

Note: I´m using browsersync to host my project and Im not using Node

Share Improve this question edited May 14, 2020 at 2:59 Juan José Jaramillo asked May 14, 2020 at 2:33 Juan José JaramilloJuan José Jaramillo 671 gold badge1 silver badge7 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 0

Since you are using the esm syntax, you will need to update the export syntax to the following.


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

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

What I think you are trying to do is this:

const earthData = require('astronomia/data/vsop87Bearth')

That will import the data you want into the vsop87Bearth variable. That variable will then have the properties you want, like earthData.L or earthData.name.

Their README file has more example: https://github./menthol/astronomia#using-a-single-package


Just a feedback, when you "import as"

import * as earth from './astronomia-master/data/vsop87Bearth.js'

You use the earth variable, not data.earth as you had.

本文标签: javascriptError Uncaught ReferenceError module is not defined when using moduleexportStack Overflow