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 02 Answers
Reset to default 0Since 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
版权声明:本文标题:javascript - Error: Uncaught ReferenceError: module is not defined when using module.export - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744669932a2618763.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论