Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with NextJS #283

Closed
ghostlexly opened this issue Sep 23, 2022 · 6 comments
Closed

Not working with NextJS #283

ghostlexly opened this issue Sep 23, 2022 · 6 comments

Comments

@ghostlexly
Copy link

facefilter npm package is not working with NextJS.

steps to reproduce:
yarn add facefilter

issue:

node_1          | SyntaxError: Cannot use import statement outside a module
node_1          |     at Object.compileFunction (node:vm:360:18)
node_1          |     at wrapSafe (node:internal/modules/cjs/loader:1055:15)
node_1          |     at Module._compile (node:internal/modules/cjs/loader:1090:27)
node_1          |     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
node_1          |     at Module.load (node:internal/modules/cjs/loader:1004:32)
node_1          |     at Function.Module._load (node:internal/modules/cjs/loader:839:12)
node_1          |     at Module.require (node:internal/modules/cjs/loader:1028:19)
node_1          |     at require (node:internal/modules/cjs/helpers:102:18)
node_1          |     at Object.facefilter (/usr/src/app/.next/server/pages/message/[uuid]/sender/video.js:112:18)
node_1          |     at __webpack_require__ (/usr/src/app/.next/server/webpack-runtime.js:33:42) {
node_1          |   page: '/message/[uuid]/sender/video'
node_1          | }
@xavierjs
Copy link
Member

xavierjs commented Sep 23, 2022

First, Hi

NextJS runs JavaScript code on the server side.
But some browser APIs like WebGL or MediaStream API cannot run on the server side. Jeeliz FaceFilter relies on WebGL and MediaStream API. So you need to tell NextJS to force execution on the client side.

To run code on the client side with NextJS you can use dynamic.
At the beginning of the component importing the AR component
( the AR Component is AppCanvas - https://github.com/jeeliz/jeelizFaceFilter/blob/master/reactThreeFiberDemo/src/js/components/AppCanvas.js )

import dynamic from 'next/dynamic'

Then:

const AppCanvasDyn = dynamic(
    () => {
      return import("AppCanvas");
    },
    { ssr: false }
  );

Then in the rendering, you render < AppCanvasDyn/> instead of <AppCanvas/>

@xavierjs
Copy link
Member

@ghostlexly does it help to make it work with NextJS?

@xavierjs
Copy link
Member

I suppose it worked so I close the issue. @ghostlexly when someone takes time to help you to solve an issue, you should at least say thank you, your mother should have taught you that.

@usama203
Copy link

I suppose it worked so I close the issue. @ghostlexly when someone takes time to help you to solve an issue, you should at least say thank you, your mother should have taught you that.

Thank you brother it really helps. I was stuck on same issue almost 3 hours.

@omgcx1222
Copy link

omgcx1222 commented Feb 29, 2024

First, Hi

NextJS runs JavaScript code on the server side. But some browser APIs like WebGL or MediaStream API cannot run on the server side. Jeeliz FaceFilter relies on WebGL and MediaStream API. So you need to tell NextJS to force execution on the client side.

To run code on the client side with NextJS you can use dynamic. At the beginning of the component importing the AR component ( the AR Component is AppCanvas - https://github.com/jeeliz/jeelizFaceFilter/blob/master/reactThreeFiberDemo/src/js/components/AppCanvas.js )

import dynamic from 'next/dynamic'

Then:

const AppCanvasDyn = dynamic(
    () => {
      return import("AppCanvas");
    },
    { ssr: false }
  );

Then in the rendering, you render < AppCanvasDyn/> instead of <AppCanvas/>

An 'ARCanvas' cannot be used as a JSX component. Its element type 'ReactElement<any, any> | Component | null' is not a valid JSX element. error message is displayed when the yarn build command is run. @types/react": "18.2.25"

`const JEELIZVTOWIDGET = useRef();
useEffect(() => {
if (!JEELIZVTOWIDGET.current) {
import("jeelizvtowidget").then((module) => {
JEELIZVTOWIDGET.current = module.JEELIZVTOWIDGET;

    init_VTOWidget({
      placeHolder,
      canvas,
      toggle_loading,
      sku: tryOnProduct.ar_model_url,
      JEELIZVTOWIDGET: JEELIZVTOWIDGET.current,
    });
  });
} else {
  JEELIZVTOWIDGET.current?.resume(true);
}

return () => {
  JEELIZVTOWIDGET.current?.destroy();
  // JEELIZVTOWIDGET?.pause(true);
};

}, [tryOnProduct.ar_model_url]);`

I use it this way, No problems with development and build, but I don't know if there are other problems

@ghostlexly
Copy link
Author

I suppose it worked so I close the issue. @ghostlexly when someone takes time to help you to solve an issue, you should at least say thank you, your mother should have taught you that.

I just never received the notifications for your messages, but thanks for the solution, even if it's late. I always appreciate the community's help here.
We never had the solution, my company has just removed the filter idea from the roadmap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants