Hello,
I am very new to both node js and Cloudflare.
I have the following program that is also a npm package: maze3d/maze3d.js at main · michaelnicol/maze3d · GitHub
npm i maze3d
The issue is that a NPM package is only for server side and can’t be used client side. As a result, I was told to import from a CDN. This also prevents cros errors.
I set up a worker here: https://dash.cloudflare.com/a455c220c3216f223c3e078de78e42d9/workers/services/view/maze3d/production
However, I am wondering how I can put the above NPM package into this worker so it can be returned? I can use import * as maze3d from <link>
I found another CDN here: https://cdn.jsdelivr.net/gh/michaelnicol/maze3d/maze3d.js
This returns my github file as a string that I can then use eval()
for. However, my request uses node js https module, which wont be on the client side.
If I do the following:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
<script type="module">
import * as maze3d from "https://cdn.jsdelivr.net/gh/michaelnicol/maze3d/maze3d.js"
console.log(maze3d)
</script>
</html>
I get that type module is not defined.
Where and how should I go from here?