konsumer / kasa_control

use kasa-cloud to hit your TPLink bulbs in nodejs
10 stars 3 forks source link

issues in newer versions of Node.js #21

Closed ryanfarber closed 11 months ago

ryanfarber commented 3 years ago

it seems kasa_control v0.1.1 doesn't wanna work with node V16

I keep getting this error

node:internal/modules/cjs/loader:1109
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/ryanfarber/code/botmaster/node_modules/kasa_control/node_modules/node-fetch/src/index.js
require() of ES modules is not supported.
require() of /Users/ryanfarber/code/botmaster/node_modules/kasa_control/node_modules/node-fetch/src/index.js from /Users/ryanfarber/code/botmaster/node_modules/kasa_control/build/lib.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/ryanfarber/code/botmaster/node_modules/kasa_control/node_modules/node-fetch/package.json.

    at new NodeError (node:internal/errors:329:5)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1109:13)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (/Users/ryanfarber/code/botmaster/node_modules/kasa_control/build/lib.js:15:13)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (/Users/ryanfarber/code/botmaster/plugins/kasa/src.js:11:21)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (/Users/ryanfarber/code/botmaster/plugins/kasa/index.js:3:18)
    at Module._compile (node:internal/modules/cjs/loader:1092:14) {
  code: 'ERR_REQUIRE_ESM'
}
konsumer commented 3 years ago

I will update it to use microbundle + es6 module. it was originally made before node native es6 worked well, and I think improving build would make it work better for everyone (even older node versions.)

konsumer commented 3 years ago

Give kasa_control@0.1.2 a try, and let me know if it works for you.

konsumer commented 11 months ago

Seems to work ok for me. Closing.