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

The requested module 'pytorchjs' is a CommonJS module, which may not support all module.exports as named exports #22

Open
raphael10-collab opened this issue Oct 21, 2021 · 3 comments

Comments

@raphael10-collab
Copy link

(base) raphy@pc:~/pytorchjsPlay$ nano basic.js

import { torch, torchvision } from 'pytorchjs';

(base) raphy@pc:~/pytorchjsPlay$ node basic.js 
file:///home/raphy/pytorchjsPlay/basic.js:1
import { torch, torchvision } from 'pytorchjs';
         ^^^^^
SyntaxError: Named export 'torch' not found. The requested module 'pytorchjs' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'pytorchjs';
const { torch, torchvision } = pkg;

    at ModuleJob._instantiate (internal/modules/esm/module_job.js:104:21)
    at async ModuleJob.run (internal/modules/esm/module_job.js:149:5)
    at async Loader.import (internal/modules/esm/loader.js:166:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5)
(base) raphy@pc:~/pytorchjsPlay$ 

basic_2,js :

import pkg from 'pytorchjs';
const { torch, torchvision } = pkg;


(base) raphy@pc:~/pytorchjsPlay$ node basic_2.js 
internal/modules/cjs/loader.js:880
  const err = new Error(message);
              ^

Error: Cannot find module '@babel/runtime/helpers/interopRequireDefault'
Require stack:
- /home/raphy/pytorchjsPlay/node_modules/pytorchjs/lib/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/home/raphy/pytorchjsPlay/node_modules/pytorchjs/lib/index.js:3:30)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:199:29) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/home/raphy/pytorchjsPlay/node_modules/pytorchjs/lib/index.js' ]
}
(base) raphy@pc:~/pytorchjsPlay$ 

package.json :

{
"type": "module",
"dependencies": {
"pytorchjs": "^0.1.5"
}
}

node : v14.15.5
OS. Ubuntu 20.04

@raghavmecheri
Copy link
Owner

Are you using yarn to install the package? And if so, are you seeing any error logs when you install?

@quan-luu
Copy link

quan-luu commented Oct 5, 2022

I faced the same problem/error as @raphael10-collab. I indeed installed the package via yarn and no error was found. Below are logs during the installation process:

yarn add v1.22.19
warning package.json: No license field
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
warning No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
warning No license field
success Saved 1 new dependency.
info Direct dependencies
└─ pytorchjs@0.1.5
info All dependencies
└─ pytorchjs@0.1.5
Done in 143.35s.

@MissArtemis
Copy link

so do I

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