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

Cannot find module 'long' error when trying to run @tensorflow/tfjs module in Node.js #6841

Closed
tamaina opened this issue Sep 20, 2022 · 5 comments

Comments

@tamaina
Copy link

tamaina commented Sep 20, 2022

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 20.04.4 LTS (Focal Fossa)
  • TensorFlow.js installed from (npm or script link): npm (using on yarn berry 3.2.1)
  • TensorFlow.js version: 3.20.0

Describe the problem
I got Cannot find module 'long' error when trying to run @tensorflow/tfjs module in Node.js.

node:internal/modules/cjs/loader:956
  const err = new Error(message);
              ^

Error: Cannot find module 'long'
Require stack:
- /home/ubuntu/misskey-dev/node_modules/.store/@tensorflow-tfjs-npm-3.20.0-3984b7fecc/node_modules/@tensorflow/tfjs/dist/tf.node.js
- /home/ubuntu/misskey-dev/node_modules/.store/nsfwjs-virtual-fe284db5a1/node_modules/nsfwjs/dist/index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
    at Module._load (node:internal/modules/cjs/loader:804:27)
    at Module.require (node:internal/modules/cjs/loader:1022:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/ubuntu/misskey-dev/node_modules/.store/@tensorflow-tfjs-npm-3.20.0-3984b7fecc/node_modules/@tensorflow/tfjs/dist/tf.node.js:24:19)
    at Module._compile (node:internal/modules/cjs/loader:1120:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
    at Module.load (node:internal/modules/cjs/loader:998:32)
    at Module._load (node:internal/modules/cjs/loader:839:12)
    at Module.require (node:internal/modules/cjs/loader:1022:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/ubuntu/misskey-dev/node_modules/.store/@tensorflow-tfjs-npm-3.20.0-3984b7fecc/node_modules/@tensorflow/tfjs/dist/tf.node.js',
    '/home/ubuntu/misskey-dev/node_modules/.store/nsfwjs-virtual-fe284db5a1/node_modules/nsfwjs/dist/index.js'
  ]
}

Node.js v18.7.0

I think this is a behavior specific to Yarn berry (I am using v3.2.1).

I think one of the reasons is that its package.json does not contain long dependency.

"dependencies": {

I got it to work by adding long to the dependency in my yarn.lock.

Why doesn't @tensorflow/tfjs include long as a dependency?

@rthadur
Copy link
Contributor

rthadur commented Sep 20, 2022

Thank you, we do not support yarnberry with tfjs .
cc @pyu10055

@rthadur rthadur self-assigned this Sep 20, 2022
@mattsoulanille
Copy link
Member

Thanks for the bug report @tamaina.

@tensorflow/tfjs depends on @tensorflow/tfjs-core, which depends on long. However, it looks like the @tensorflow/tfjs/dist/tf.node.js bundle is trying to require('long'); even while it imports @tensorflow/tfjs-core. @tensorflow/tfjs has no reference to long in its src/ directory, so this doesn't seem right.

This works fine in yarn 1.x.x, but maybe yarn berry has stricter (and more correct) dependency resolution. I'll look into why the node bundle has the line var LongExports = require('long');

@rthadur rthadur assigned mattsoulanille and unassigned rthadur Sep 30, 2022
@gaikwadrahul8
Copy link
Contributor

Hi, @tamaina

Apologize for the delayed response and It seems like this issue has been taken care after merging this PR #8764 and now we are able to include long as a dependency in @tensorflow/tfjs by using npm i long command and I tried it's working as expected, for your reference I have added package.json file details below and if have I missed something here please let me know or Could you please confirm if this issue is resolved for you ? Please feel free to close the issue if it is resolved ? Thank you!

{
  "dependencies": {
    "@tensorflow/tfjs": "^4.1.0",
    "@tensorflow/tfjs-backend-webgl": "^4.2.0",
    "@tensorflow/tfjs-core": "^4.2.0",
    "@tensorflow/tfjs-node": "^4.2.0",
    "long": "^5.2.1",
    "node-dns": "^0.1.0",
    "node-fetch": "^3.3.1"
  },
  "type": "module"
}



@tamaina
Copy link
Author

tamaina commented Apr 4, 2023

With yarn, the issue of missing dependencies could be solved by editing .yarnrc.yml.

However, our project is now using pnpm. We have no problem.

Thanks for your reply.

@tamaina tamaina closed this as not planned Won't fix, can't repro, duplicate, stale Apr 4, 2023
@google-ml-butler
Copy link

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

@gaikwadrahul8 gaikwadrahul8 self-assigned this Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants