hiukim / mind-ar-js

Web Augmented Reality. Image Tracking, Face Tracking. Tensorflow.js
MIT License
2.14k stars 394 forks source link

Es modules are containing require when using mindar-image-three.prod.js #325

Closed roelvanhintum closed 1 year ago

roelvanhintum commented 1 year ago

Vite (in a sveltekit project) throws the following error when building my app using the image three package. I think it's the imported tensorflow code, but i can't figure out how to fix it (i tried forking and building this project myself).

import { MindARThree } from 'mind-ar/dist/mindar-image-three.prod.js';
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and 'package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at new MC (file:///.../node_modules/mind-ar/dist/controller.03a2d8ae.js:3585:5)
nikoyanakiev commented 1 year ago

I also can't build the local project following the steps given in the " Development Guide" notes, having the same error:

file:///C:/Users/antoaneta/Documents/nodejs/mind-ar-js-master/dist/controller.03a2d8ae.js:3585 this.util = require("util"), this.textEncoder = new this.util.TextEncoder(); ^

ReferenceError: require is not defined in ES module scope, you can use import instead

I even had to copy the whole folder \three\examples\jsm to \three\addons to run reach here. Feels like some prerequisites are not described.

roelvanhintum commented 1 year ago

See for a proposed solution: #326

nikoyanakiev commented 1 year ago

Have to admit I understood the usage wrong. Downloaded roelvanhintum's branch, and currently it works on my side perfectly. Even deployed on a webserver and now my apps do work. Thanks a lot, for me is now clear how mindar should be used :) By the way - mindar is GGGGrrrrreat! !!

hiukim commented 1 year ago

I tried to import mindar-image-three.prod.js in a create-react-app which works.

Reference: https://github.com/hiukim/mind-ar-js-react

Not sure about sveltekit

hiukim commented 1 year ago

fixed some import issue in v1.2.2. Perhaps it's solved. Feel free to re-open if not.