peter-murray / node-hue-api

Node.js Library for interacting with the Philips Hue Bridge and Lights
Apache License 2.0
1.19k stars 145 forks source link

Cannot import createLocal using TypeScript #223

Closed pindab0ter closed 2 years ago

pindab0ter commented 2 years ago

When trying to import createLocal it's telling me it can't resolve it:

import { createLocal } from "node-hue-api/lib/api";
// build failed (src/hue/index.ts:4:28 import { createLocal } from "node-hue-api/lib/api";): Could not resolve "node-hue-api/lib/api"

Other imports like discovery work fine.

peter-murray commented 2 years ago

The packages are distributed in the dist not lib directory for this module, please update the import to use the dist files and let me know if that is still an issue.

pindab0ter commented 2 years ago

This is what I've tried:

import Api from "node-hue-api/dist/esm/api/Api";
import { createLocal } from "node-hue-api/dist/esm/api";

PHPStorm is not aware of any problems, but when I try to build, this is the error I'm getting:

build failed (src/hue/index.ts:3:28 import { createLocal } from "node-hue-api/dist/esm/api";): Could not resolve "node-hue-api/dist/esm/api"

Same goes if I substitute esm for cjs.

A workaround is to do this instead, but I'd rather know how to do it without:

import { v3 } from "node-hue-api";

v3.api.createLocal(…);
pindab0ter commented 2 years ago

Specifying Api as a return type was giving me trouble. The solution was this:

import { discovery, v3 } from "node-hue-api";
import { Api } from "node-hue-api/dist/esm/api/Api";

What threw me off was having to import Api which was specified in the file Api which was a part of the folder api.

I would suggest improving this.