Skip to content

Can not import ESM bundle for browser with NextJS 14 #418

@tembra

Description

@tembra

Issue Description

When importing Human on a NextJS 14 project, the framework tries to import the node bundle instead of ESM for browsers, despite adding 'use client' on top of the page file.

Since node bundle requires a tfjs backend, the error below comes in:

./node_modules/@vladmandic/human/dist/human.node.js:7:1678
Module not found: Can't resolve '@tensorflow/tfjs-node'

I know that this is not an issue within the Human package at all and it's about NextJS SSR. However I guess you may help me to achieve the desired solution.

I already tried to load Human within a separated dynamic loaded component with dynamic(() => import('@/components/Human'), { ssr: false }), but it also did not work.

I also tried to import it inside a useEffect of the Human component created as you did in your class constructor in NextJS demo, but it also did not work.

I also tried to import Human explicitly from @vladmandic/human/dist/human.esm but it did not found the path.

Everything works fine if I use Vite instead of NextJS to create my project.

Steps to Reproduce

  1. Create a new project with npx create-next-app app-name and choose all default configs.
  2. Run npm i
  3. Change app/page.tsx to add 'use client' on top the file and add import to Human import { Human } from '@vladmandic/human.
  4. Run npm run dev
  5. Access the URL on your browser

Expected Behavior

NextJS identify that I'm using a client component on that page and load ESM bundle of Human package instead of node bundle.

Environment

  • Human library version? 3.2.0
  • Built-in demo or custom code? Custom code. Just create a project and import Human.
  • Type of module used (e.g. js, esm, esm-nobundle)? esm
  • TensorFlow/JS version (if not using bundled module)?
  • Browser or NodeJS and version (e.g. NodeJS 14.15 or Chrome 89)? Arc 1.28.0
  • OS and Hardware platform (e.g. Windows 10, Ubuntu Linux on x64, Android 10)? macOS 14.2.1 on M2 Pro (arm64)
  • Packager (if any) (e.g, webpack, rollup, parcel, esbuild, etc.)?
  • Framework (if any) (e.g. React, NextJS, etc.)? NextJS

Diagnostics

Additional

  • For installation or startup issues include your package.json
  • For usage issues, it is recommended to post your code as gist
  • For general questions, create a discussion topic

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions