tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.48k stars 1.93k forks source link

[@tfjs-models/pose-detection] Dependency tree build issue #7784

Closed evanmartiin closed 1 year ago

evanmartiin commented 1 year ago

Problems

When installing with pnpm it works, but when installing with npm, I have a dependency tree issue (see Error 1). When building on Netlify, I have a dependency resolve issue (see Error 2).

I'm using only @mediapipe/pose: ^0.5.1675469404 and @tensorflow-models/pose-detection: ^2.1.0 and I can't build my project.

I think the @tensorflow-models/pose-detection's peer dependencies needs different versions of @tensorflow/tfjs-core.

Do you know how can I fix that please ? 🙏


System information


Error 1 - npm install on local

npm WARN ERESOLVE overriding peer dependency
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: @tensorflow/tfjs-backend-webgpu@0.0.1-alpha.20
npm ERR! Found: @tensorflow/tfjs-core@4.8.0
npm ERR! node_modules/@tensorflow/tfjs-core
npm ERR!   peer @tensorflow/tfjs-core@"4.5.0" from @tensorflow/tfjs-backend-cpu@4.5.0
npm ERR!   node_modules/@tensorflow/tfjs-backend-webgpu/node_modules/@tensorflow/tfjs-backend-cpu
npm ERR!     @tensorflow/tfjs-backend-cpu@"4.5.0" from @tensorflow/tfjs-backend-webgpu@0.0.1-alpha.20
npm ERR!     node_modules/@tensorflow/tfjs-backend-webgpu
npm ERR!       peer @tensorflow/tfjs-backend-webgpu@"^0.0.1-alpha.17" from @tensorflow-models/pose-detection@2.1.0
npm ERR!       node_modules/@tensorflow-models/pose-detection
npm ERR!         @tensorflow-models/pose-detection@"^2.1.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer @tensorflow/tfjs-core@"4.5.0" from @tensorflow/tfjs-backend-webgpu@0.0.1-alpha.20
npm ERR! node_modules/@tensorflow/tfjs-backend-webgpu
npm ERR!   peer @tensorflow/tfjs-backend-webgpu@"^0.0.1-alpha.17" from @tensorflow-models/pose-detection@2.1.0
npm ERR!   node_modules/@tensorflow-models/pose-detection
npm ERR!     @tensorflow-models/pose-detection@"^2.1.0" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: @tensorflow/tfjs-core@4.5.0
npm ERR! node_modules/@tensorflow/tfjs-core
npm ERR!   peer @tensorflow/tfjs-core@"4.5.0" from @tensorflow/tfjs-backend-webgpu@0.0.1-alpha.20
npm ERR!   node_modules/@tensorflow/tfjs-backend-webgpu
npm ERR!     peer @tensorflow/tfjs-backend-webgpu@"^0.0.1-alpha.17" from @tensorflow-models/pose-detection@2.1.0
npm ERR!     node_modules/@tensorflow-models/pose-detection
npm ERR!       @tensorflow-models/pose-detection@"^2.1.0" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

Error 2 - npm run build on Netlify

11:35:31 PM: vite v4.1.1 building for production...
11:35:31 PM: transforming...
11:35:32 PM: ✓ 64 modules transformed.
11:35:32 PM: [vite]: Rollup failed to resolve import @tensorflow/tfjs-core from /opt/build/repo/node_modules/.pnpm/@tensorflow-models+pose-detection@2.1.0_vhenez4ue6iz45b7odzlwbnzde/node_modules/@tensorflow-models/pose-detection/dist/pose-detection.esm.js.
11:35:32 PM: This is most likely unintended because it can break your application at runtime.
11:35:32 PM: If you do want to externalize this module explicitly add it to
11:35:32 PM: `build.rollupOptions.external`
11:35:32 PM: error during build:
11:35:32 PM: Error: [vite]: Rollup failed to resolve import @tensorflow/tfjs-core from /opt/build/repo/node_modules/.pnpm/@tensorflow-models+pose-detection@2.1.0_vhenez4ue6iz45b7odzlwbnzde/node_modules/@tensorflow-models/pose-detection/dist/pose-detection.esm.js.
11:35:32 PM: This is most likely unintended because it can break your application at runtime.
11:35:32 PM: If you do want to externalize this module explicitly add it to
11:35:32 PM: `build.rollupOptions.external`
11:35:32 PM:     at onRollupWarning (file:///opt/build/repo/node_modules/.pnpm/vite@4.1.1_sass@1.58.0/node_modules/vite/dist/node/chunks/dep-3007b26d.js:44772:19)
11:35:32 PM:     at onwarn (file:///opt/build/repo/node_modules/.pnpm/vite@4.1.1_sass@1.58.0/node_modules/vite/dist/node/chunks/dep-3007b26d.js:44542:13)
11:35:32 PM:     at Object.onwarn (file:///opt/build/repo/node_modules/.pnpm/rollup@3.15.0/node_modules/rollup/dist/es/shared/rollup.js:24651:13)
11:35:32 PM:     at ModuleLoader.handleInvalidResolvedId (file:///opt/build/repo/node_modules/.pnpm/rollup@3.15.0/node_modules/rollup/dist/es/shared/rollup.js:23335:26)
11:35:32 PM:     at file:///opt/build/repo/node_modules/.pnpm/rollup@3.15.0/node_modules/rollup/dist/es/shared/rollup.js:23295:26
11:35:32 PM: ​
11:35:32 PM: build.command failed                                        
11:35:32 PM: ────────────────────────────────────────────────────────────────
11:35:32 PM: ​
11:35:32 PM:   Error message
11:35:32 PM:   Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
11:35:32 PM: ​
11:35:32 PM:   Error location
11:35:32 PM:   In Build command from Netlify app:
11:35:32 PM:   npm run build
11:35:32 PM: ​
11:35:32 PM:   Resolved config
11:35:32 PM:   build:
11:35:32 PM:     command: npm run build
11:35:32 PM:     commandOrigin: ui
11:35:32 PM:     environment:
11:35:32 PM:       - CI
11:35:32 PM:       - REVIEW_ID
11:35:32 PM:     publish: /opt/build/repo/dist
11:35:32 PM:     publishOrigin: ui
11:35:34 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:35:34 PM: Failing build: Failed to build site
gaikwadrahul8 commented 1 year ago

Hi, @evanmartiin

Thank you for reporting this issue and May I know have you tried with yarn package manager please ? I tried from my end with yarn to install all package dependancies and it's working as expected. For your reference I have added screenshot below. Meanwhile I will try to use npm package manager to use pose-detection model from my end and I'll let you know but give it try with yarn package manager from your end and let us know whether is it working as expected or not ?

Please follow below steps :

  1. Clone github repo using below command in the terminal git clone https://github.com/tensorflow/tfjs-examples.git
  2. Go to pose-detection folder using this command cd tfjs-examples/react-native/pose-detection
  3. run only yarn command in the terminal ( To install all package dependancies mentioned in the package.json)
  4. Finally run yarn start in the terminal

Here is screenshot :

gaikwadrahul-macbookpro:TFJS-Cloned-Repo-For-Testing gaikwadrahul$ cd tfjs-examples/
gaikwadrahul-macbookpro:tfjs-examples gaikwadrahul$ cd react-native/
gaikwadrahul-macbookpro:react-native gaikwadrahul$ cd pose-detection/
gaikwadrahul-macbookpro:pose-detection gaikwadrahul$ pwd
/Users/gaikwadrahul/Desktop/TFJS-Cloned-Repo-For-Testing/tfjs-examples/react-native/pose-detection
gaikwadrahul-macbookpro:pose-detection gaikwadrahul$ yarn
yarn install v1.22.19
[1/4] 🔍  Resolving packages...
success Already up-to-date.
✨  Done in 0.27s.
gaikwadrahul-macbookpro:pose-detection gaikwadrahul$ yarn start
yarn run v1.22.19
$ expo start
Starting project at /Users/gaikwadrahul/Desktop/TFJS-Cloned-Repo-For-Testing/tfjs-examples/react-native/pose-detection
Some dependencies are incompatible with the installed expo version:
  expo-camera@12.3.0 - expected version: ~12.5.0
  react-native@0.69.3 - expected version: 0.69.9
Your project may not work correctly until you install the correct versions of the packages.
Install individual packages by running npx expo install expo-camera@~12.5.0 react-native@0.69.9
Starting Metro Bundler
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█ ▄▄▄▄▄ █   █▄▀▀▄▀█ ▄▄▄▄▄ █
█ █   █ █ ▀▄ █▀▄ ▄█ █   █ █
█ █▄▄▄█ █▀██▀▀ ▀▄██ █▄▄▄█ █
█▄▄▄▄▄▄▄█▄▀▄█ █▄█ █▄▄▄▄▄▄▄█
█  ██▄▄▄██▀▀▄▀▀▄ ▄██ ▀▄▄ ▄█
██ ▄ █ ▄ ██▀ ▄██ ▀▀  ▄  ▀██
█▀ ▄  ▄▄ ▄▀▄█▄▀▄▀▄▀▄▀▀▄ ▀██
███▀▀▀▄▄▄▀ ▀█▀██▄▄ ██▄ ▀███
█▄▄▄▄██▄▄ ▄ ▄▀▄ ▄ ▄▄▄ ▀ ▄▄█
█ ▄▄▄▄▄ █▀▄▀ ▄ ▄▀ █▄█ ▀▀███
█ █   █ █▄ ▄█▄ ▀█▄▄ ▄▄▀   █
█ █▄▄▄█ █▀███▀█▀▄▄▄ ▀█▀▀ ██
█▄▄▄▄▄▄▄█▄█▄▄█▄▄████▄▄▄▄▄▄█

› Metro waiting on exp://127.0.0.1:19000
› Scan the QR code above with Expo Go (Android) or the Camera app (iOS)

› Press a │ open Android
› Press i │ open iOS simulator
› Press w │ open web

› Press r │ reload app
› Press m │ toggle menu

› Press ? │ show all commands

Logs for your project will appear below. Press Ctrl+C to exit.
evanmartiin commented 1 year ago

@gaikwadrahul8 thanks for your answer !

I tried running tfjs-examples/react-native/pose-detection with yarn as you said, here is what I had on the page :

{"name":"pose-detection-expo","slug":"pose-detection-expo","version":"1.0.0","assetBundlePatterns":("*/"],"_internal":{"isDebug":false,"projectRoot":"[rootToExample]/.../tfjs-examples/react-native/pose-detection","dynamicConfigPath":null,"staticConfigPath":"[rootToExample]/.../tfjs-examples/react-native/pose-detection/app.json","packageJsonPath":"[rootToExample]/.../tfjs-examples/react-native/pose-detection/package.json"},"sdkVersion":"46.0.0","platforms":("ios","android"],"debuggerHost":"172.20.10.6:19000","logUrl":"http://172.20.10.6:19000/logs","developer":{"tool":"expo-cli","projectRoot":"[rootToExample]/.../tfjs-examples/react-native/pose-detection"},"packagerOpts":{"dev":true},"mainModuleName":"index","__flipperHack":"React Native packager is running","hostUri":"172.20.10.6:19000","bundleUrl":"http://172.20.10.6:19000/index.bundle?platform=ios&dev=true&hot=false","id":"@anonymous/pose-detection-expo-d56e8e08-fbfe-4e8c-b48a-bf9bf76739d0"}

Also, I tried, re-installing my own project with yarn instead of pnpm, and I had this error :

✘ [ERROR] Failed to resolve entry for package "ms". The package may have incorrect main/module/exports specified in its package.json. [plugin vite:dep-pre-bundle]

    node_modules/esbuild/lib/main.js:1360:21:
      1360 │         let result = await callback({
           ╵                      ^

    at packageEntryFailure (.../node_modules/vite/dist/node/chunks/dep-e8f070e8.js:23382:11)
    at resolvePackageEntry (.../node_modules/vite/dist/node/chunks/dep-e8f070e8.js:23379:5)
    at tryNodeResolve (.../node_modules/vite/dist/node/chunks/dep-e8f070e8.js:23113:20)
    at Context.resolveId (.../node_modules/vite/dist/node/chunks/dep-e8f070e8.js:22874:28)
    at Object.resolveId (.../node_modules/vite/dist/node/chunks/dep-e8f070e8.js:42847:46)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async .../node_modules/vite/dist/node/chunks/dep-e8f070e8.js:64148:21
    at async .../node_modules/vite/dist/node/chunks/dep-e8f070e8.js:23689:34
    at async requestCallbacks.on-resolve (.../node_modules/esbuild/lib/main.js:1360:22)
    at async handleRequest (.../node_modules/esbuild/lib/main.js:723:13)

  This error came from the "onResolve" callback registered here:

    node_modules/esbuild/lib/main.js:1279:20:
      1279 │       let promise = setup({
           ╵                     ^

    at setup (.../node_modules/vite/dist/node/chunks/dep-e8f070e8.js:23669:19)
    at handlePlugins (.../esbuild/lib/main.js:1279:21)
    at buildOrContextImpl (.../node_modules/esbuild/lib/main.js:968:5)
    at Object.buildOrContext (.../node_modules/esbuild/lib/main.js:776:5)
    at .../node_modules/esbuild/lib/main.js:2172:68
    at new Promise (<anonymous>)
    at Object.context (.../node_modules/esbuild/lib/main.js:2172:27)
    at Object.context (.../node_modules/esbuild/lib/main.js:2012:58)
    at prepareEsbuildOptimizerRun (.../node_modules/vite/dist/node/chunks/dep-e8f070e8.js:44450:35)

  The plugin "vite:dep-pre-bundle" was triggered by this import

    node_modules/debug/src/common.js:14:32:
      14 │   createDebug.humanize = require('ms');
         ╵               
gaikwadrahul8 commented 1 year ago

Hi, @evanmartiin

It seems like this issue is coming from vite and package ms if I'm not wrong because I tried on my MacOs and it's working as expected so could you please give it try without vite and check whether is it working as expected or not ?

If possible could you please share your package.json file with us ? Please try to re-install ms package by using this command npm install ms

If issue still persists without vite please share error log to do further investigation on your issue ? Thank you!

github-actions[bot] commented 1 year ago

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

github-actions[bot] commented 1 year ago

This issue was closed due to lack of activity after being marked stale for past 7 days.

google-ml-butler[bot] commented 1 year ago

Are you satisfied with the resolution of your issue? Yes No