-1

I am kind of unfamiliar with running javascript from command line, but I am in a situation where need to use a NPM package for a Panasonic AC, that has a wrapper for their unofficial API.

However, I want to make a simple JS that I can run from command line, that will import the NPM package. But this only generates error:

(node:68628) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/Ronny/Documents/AC/index.js:1
import { ComfortCloudClient } from 'panasonic-comfort-cloud-client'
^^^^^^

SyntaxError: Cannot use import statement outside a module

Is it not possible to do this?

rebellion
  • 6,628
  • 11
  • 48
  • 79
  • Depends on your node version and the package itself. See https://stackoverflow.com/questions/45854169/how-can-i-use-an-es6-import-in-node – Phix Aug 26 '20 at 20:21

1 Answers1

1

Its possible using node require() function

const { ComfortCloudClient } = require('panasonic-comfort-cloud-client')
  • This fixed the error message, but now it says "ReferenceError: client is not defined". So it seems like there's more to it. – rebellion Aug 26 '20 at 20:46