Code Monkey home page Code Monkey logo

Comments (6)

Garbee avatar Garbee commented on May 26, 2024 2

Just in case anyone else hits this. I am using Node v14.18.2 with the mjs extension to use ES6 imports. The examples all show import otaClient from '@crowdin/ota-client'; however upon trying to create a new object it failed since this does not make otaClient a constructor. I instead had to end up doing const client = new otaClient.default(hash);.

Upon logging, you will see the default example creating an object with the default property containing the constructor. The import rename syntax also does NOT work here, import {default as otaClient} from '@crowdin/ota-client';. This still makes otaClient the object with a default property.

Could be a bug in Node or a general issue with packaging modules. Just a note here in case anyone else comes across this with es6 module imports too.

from ota-client-js.

yevheniyJ avatar yevheniyJ commented on May 26, 2024

@ferreiro hi there! Could you please share the part of code with the import/require statement? And also would be nice to know which version of the library you are using. Thanks!

from ota-client-js.

yevheniyJ avatar yevheniyJ commented on May 26, 2024

It looks to me that problem is not in Node itself but rather in wrong import of OtaClient

from ota-client-js.

ferreiro avatar ferreiro commented on May 26, 2024

hey @yevheniyJ sorry for the delay :/ I've tried several things:

const otaClient = require('@crowdin/ota-client');

console.log(otaClient);
const hash = '{distribution_hash}';
const client = new otaClient(hash);

// get list of files in distribution
client
 	.listFiles()
 	.then(files => console.log(file))
 	.catch(error => console.error(error));
const {otaClient} = require('@crowdin/ota-client');

console.log(otaClient);
const client = new otaClient('{distribution_hash}');

// get list of files in distribution
client
 	.listFiles()
 	.then(files => console.log(file))
 	.catch(error => console.error(error));

both of them produced the same error...

However, I figured out how to make it work...

const otaClient = require('@crowdin/ota-client');
const client = new otaClient.default('{distribution_hash}');

so I needed to use otaClient.default, so the instructions in the readme are wrong. Can you update this to work for this:

const otaClient = require('@crowdin/ota-client');
const client = new otaClient.default(hash);

from ota-client-js.

yevheniyJ avatar yevheniyJ commented on May 26, 2024

@ferreiro hi hi!) good that you found solution. I suggest to move default suffix to the require section. So in the end you should have smth like this : const otaClient = require(β€œ@crowdin/ota-client”).default; and later on create an instance without default keyword. In my eyes it is more understandable πŸ™‚

from ota-client-js.

yevheniyJ avatar yevheniyJ commented on May 26, 2024

And in readme we are using ES6 import/export syntax and it is correct. I will just add another example with Node.js require option.

from ota-client-js.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.