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

Error when deployed on Heroku, potentially due to minification #157

Closed
dancherb opened this issue Mar 3, 2023 · 4 comments
Closed

Error when deployed on Heroku, potentially due to minification #157

dancherb opened this issue Mar 3, 2023 · 4 comments
Assignees
Labels
question Further information is requested

Comments

@dancherb
Copy link

dancherb commented Mar 3, 2023

Issue Description

When the project is built and deployed on Heroku, the following error appears. This error does not appear when using the standard face-api.js npm package:
Uncaught SyntaxError: Invalid left-hand side expression in postfix operation

This references the following minified code:
async nextState(e){await e;let t=await wF(this.iterators,function(e){return e instanceof wJ?{value:e.next().then(e=>(0++,e.done&&0++,e.value)),recurse:!1}:{value:null,recurse:!0}});

It seems that "0++" is causing the issue here. This appears to be minified from the following function in @tensorflow\tfjs\node_modules\@tensorflow\tfjs-data\src\iterators\lazy_iterator.ts. It appears that the variables numIterators and iteratorsDone are reduced to simply 0, thus giving the code 0++.

let numIterators = 0;
 let iteratorsDone = 0;
 
 function getNext(container: IteratorContainer): DeepMapAsyncResult {
   if (container instanceof LazyIterator) {
     const result = container.next();
     return {
       value: result.then(x => {
         numIterators++;
         if (x.done) {
           iteratorsDone++;
         }
         return x.value;
       }),
       recurse: false
     };
   } else {
     return {value: null, recurse: true};
   }
 }

**Environment

  • Module version? @vladmandic/face-api": "^1.7.9", "@tensorflow/tfjs-node": "4.2.0",
  • Built-in demo or custom code? Custom code based on built-in demo.
  • Type of module used (e.g. js, esm, esm-nobundle)? ESM.
  • Browser or NodeJS and version (e.g. NodeJS 14.15 or Chrome 89)? Node 16.x, occurs on all Chromium browsers.
  • OS and Hardware platform (e.g. Windows 10, Ubuntu Linux on x64, Android 10)? Hosted with next.js and node.js on Heroku stack 22 (Ubuntu 22.04).
  • Packager (if any) (e.g, webpack, rollup, parcel, esbuild, etc.)? Next.js 13.1.6
@vladmandic
Copy link
Owner

good job on tracing it down. it seems this will need a fix from core tfjs libs, not faceapi.
but for that, need to narrow it down:

  1. is this issue Heroku specific or does it happen with local NextJS deployment?
  2. can you create a reproduction using core tfjs (without faceapi)

if you manage to prove (1), i can help with (2) and then work directly with tfjs team on resolution.

@vladmandic vladmandic added the question Further information is requested label Mar 3, 2023
@vladmandic
Copy link
Owner

@dancherb any updates?

@dancherb
Copy link
Author

dancherb commented Mar 8, 2023

Hey @vladmandic, thanks for checking in - I managed to work around this issue by passing swcMinify: false in next.config.js. I hoped this would use a different minification process which would avoid the error, and it did! So a bit of a lazy solution but hey 💃

@vladmandic
Copy link
Owner

glad you found it!

btw, per Vercel, swcMinify is had quite a few issues in the past:

anyhow, I'm closing the issue for now, feel free to post further with any questions/comments/concerns.

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

No branches or pull requests

2 participants