mgcrea/node-tydom-client

SyntaxError: The requested module 'tydom-client' does not provide an export named 'createClient'

Closed this issue · 8 comments

Hi, new to node.js, could you please elaborate about how to use the module and the scripts ?

I installed it as guided, copied your simple client in a tydom.mjs file then tried node tydom.js (where i put my hostname, etc), but i got the error :

# node tydom.mjs (node:24059) ExperimentalWarning: The ESM module loader is experimental. file:///home/will/tydom.mjs:5 import {createClient} from 'tydom-client'; ^^^^^^^^^^^^ SyntaxError: The requested module 'tydom-client' does not provide an export named 'createClient' at ModuleJob._instantiate (internal/modules/esm/module_job.js:91:21) at async ModuleJob.run (internal/modules/esm/module_job.js:106:20) at async Loader.import (internal/modules/esm/loader.js:133:24)

I wish i could use it in nodered with home assistant...
Sorry if it's not the place to ask.

You should try without using modules in a plain .js file:

const {createClient} = require('tydom-client');

Actually the issue is that --experimental-modules doesn't support importing named exports from a commonjs module (except node's own built-ins) yet.

So another working code would be:

import tydomClient from 'tydom-client';
const {createClient} = tydomClient;

Thanks for the quick reply ! ;) And for the work !

New error since :

`root@HASSIOBIAN:/home/will# node tydom.js
internal/modules/cjs/loader.js:957
throw err;
^

Error: Cannot find module '@babel/runtime/helpers/interopRequireWildcard'
Require stack:

  • /home/will/node_modules/tydom-client/lib/index.js
  • /home/will/tydom.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:954:17)
    at Function.Module._load (internal/modules/cjs/loader.js:847:27)
    at Module.require (internal/modules/cjs/loader.js:1016:19)
    at require (internal/modules/cjs/helpers.js:69:18)
    at Object. (/home/will/node_modules/tydom-client/lib/index.js:3:31)
    at Module._compile (internal/modules/cjs/loader.js:1121:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
    at Module.load (internal/modules/cjs/loader.js:976:32)
    at Function.Module._load (internal/modules/cjs/loader.js:884:14)
    at Module.require (internal/modules/cjs/loader.js:1016:19) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
    '/home/will/node_modules/tydom-client/lib/index.js',
    '/home/will/tydom.js'
    ]
    }`

My tydom.js :

`// Required when testing against a local Tydom hardware
// to fix "self signed certificate" errors
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

//import {createClient} from 'tydom-client';
const {createClient} = require('tydom-client');

const username = '';
const password = '
';
const hostname = '192.168..'; //'mediation.tydom.com'; // or '192.168.1.xxx'

const client = createClient({username, password, hostname});

(async () => {
console.log(Connecting to "${hostname}"...);
const socket = await client.connect();
// Get Tydom info
const info = await client.get('/info');
console.dir({info});
// Turn a light on
await client.put(/devices/${MY_DEVICE_ID}/endpoints/${MY_DEVICE_ID}/data, [
{
name: 'level',
value: 100
}
]);
})();`

`root@HASSIOBIAN:/home/will# node tydom.js
(node:5037) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
/home/will/tydom.js:5
import tydomClient from 'tydom-client';
^^^^^^

SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:1043:16)
at Module._compile (internal/modules/cjs/loader.js:1091:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
at Module.load (internal/modules/cjs/loader.js:976:32)
at Function.Module._load (internal/modules/cjs/loader.js:884:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:67:12)
at internal/main/run_main_module.js:17:47
root@HASSIOBIAN:/home/will# mv tydom.js tydom.mjs
root@HASSIOBIAN:/home/will# node tydom.mjs
(node:5228) ExperimentalWarning: The ESM module loader is experimental.
internal/modules/cjs/loader.js:954
const err = new Error(message);
^

Error: Cannot find module '@babel/runtime/helpers/interopRequireWildcard'
Require stack:

  • /home/will/node_modules/tydom-client/lib/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:954:17)
    at Function.Module._load (internal/modules/cjs/loader.js:847:27)
    at Module.require (internal/modules/cjs/loader.js:1016:19)
    at require (internal/modules/cjs/helpers.js:69:18)
    at Object. (/home/will/node_modules/tydom-client/lib/index.js:3:31)
    at Module._compile (internal/modules/cjs/loader.js:1121:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
    at Module.load (internal/modules/cjs/loader.js:976:32)
    at Function.Module._load (internal/modules/cjs/loader.js:884:14)
    at ModuleWrap. (internal/modules/esm/translators.js:117:15) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [ '/home/will/node_modules/tydom-client/lib/index.js' ]
    }`

tried with your last suggestion ;)

You should set "type": "module" in your package.json

For the @babel/runtime/helpers/interopRequireWildcard I've just release a v0.4.1 that fixes it, update your package.json and npm i / yarn

Working :) Time to play with it !

Any idea about how i can use it in nodered by the way ? (If you have a lead i could save me a lot of time and nerves :))

Could be really useful and compatible with almost all good home automation systems !

Thanks a lot for your work !