-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Odd import naming (on version 5 branch) #190
Comments
It seems that quite a few types aren't exported either: declare type LightStateType = model.LightState | KeyValueType;
declare type LightId = number | string | model.Light;
declare type LightsType = model.Light | model.Luminaire | model.Lightsource; none of these are exported at all so I can't use them in my code when I want to use the same type. For example: public async hueApiSetLightState(id: string, state: LightStateType) {
const api = await this.hueApi;
api.lights.setLightState(id, state).then(undefined, (err) => {
if (err)
this.emit('warning', err.message);
})
}; |
Thanks for the information, appreciate it. I am still trying to wrap up a lot of the exports as I need to be backwards compatible whilst moving this across to TypeScript. I don't necessarily want to export everything, as that will constrain me from making implementation changes in the future. This is still a first pass on the TypeScript conversion as I need to remove the |
I would say any types exposed on a public function like the ones I show above should be exported to prevent issues like not being able to proxy a function call. |
I have a new version |
@peter-murray I also have some problems with importing it with ESM instead of CJS. Maybe I'm doing something wrong, but if I use something like that: import { discovery } from 'node-hue-api' ...I get the message that your module is a Common JS module, but if I use this one: import hue from 'node-hue-api'
const { discovery } = hue ...I get an error either, telling me that the discovery module isn't an ESM module at all:
I'm using the latest beta 2 and can't use |
I have been dual building these releases now and they "seem" to have these issues flushed out in the later builds. Can you try |
@peter-murray I just updated to the beta 4 and tried both approaches again. Sadly I got the same errors: First version:
Second version:
I use NVM with the LTS version of node (14.17.3). |
Hi @mirkoschubert, I have looked a little further into this and managed to replicate something similar to what you report when I do not use the Are you building a Node.js project or a web based project with the library, also are sin plain JavaScript or TypeScript when this is happening? If you have a bare bones example that you can share it would aid me in diagnosing the exact problem, but I am continuing the investigate this. |
@peter-murray Seeing this issue with
In addition, I noticed the |
@lsphillips Thank you for the Gist, it provided me with the ability to properly diagnose this. It is a horrible manifestation of the CommonJS/ESM dual packaging mess that exists inside Node.js when you are trying to straddle the divide and provide a single code base that properly supports the two module systems. I think I have this now resolved in |
The ESM code is generated from the TypeScript compiler, so I am still looking into whether or not there is a configuration option on the extension that I can utilize. |
@peter-murray Sorry for the delay! I tried out
I'm relatively new to the ESM type importing scheme, so maybe the error is on my end. But you can test it out for yourself: https://github.com/mirkoschubert/hue-cli In I'm using the |
You need to add the |
Currently to get hold of the
createLocal
function I am having to do this:Or:
which is not great!
Much better would just be:
I recommend barrels to export all from each folder so everything is available from the plain import. Removes and deep paths into the package and makes moving things around in a refactor much easier as you don't break the external interface.
The text was updated successfully, but these errors were encountered: