I can't seem to import dat.gui into javascript;
I'm using
import * as dat from 'dat.gui';
const gui = new dat.GUI();
When I run my code an error shows stating: Uncaught SyntaxError: Cannot use import statement outside a module. I've tried adding type='module' to the script but it didn't end up working. I was wondering if anyone has run into the same issue and could help me out, thanks.
Once the library is loaded, you can access it via window.dat
or simply dat
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>dat.gui Example</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.9/dat.gui.min.js" integrity="sha512-WoO4Ih0CDOSLYafy22wZD/mcJ7k0ESLqtQsFa6zFKnEUrbtuGU+GkLtVhgt93xa2qewG5gKEC6CWlN8OaCTSVg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
if(dat != null) {
alert("dat is working!");
const gui = new dat.GUI();
if(gui != null) {
alert("gui is working too!");
}
}
</script>
</body>
</html>
When you are going with NodeJS, you can import
(ES6) or require
(CommonJS).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.