-
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
Export as esm module #220
Comments
What version are you trying this with? The package is supposedly compatible with ESM and CommonJS, I have done some testing on this from the If you can provide more context as to where and how you are trying to consume this as ESM then I can validate and test against this in the future updates. |
Same for me, it's saying
when I try to import anything. Node v16.14.0 |
I ran into this exact problem, so +1. This branch shows this problem, wherein just by importing the library, I get the above error. |
Looking into this example you provided, adding |
What worked was using this custom loader: https://github.com/nodejs/loaders-test/tree/main/commonjs-extension-resolution-loader, e.g. However, it seems the issue is because Mandatory file extensions is not followed, i.e. relative imports don't specify file extensions. Adding The invalid JavaScript is emitted by TypeScript and there's a discussion about that here: microsoft/TypeScript#42151 Seems like the only viable solution today is to add the |
Unfortunately I couldn't get it to work at all as is... (using It seems we have to go through the complete source and add Did anyone find a solution for this? Or will there be a fix? (I'm using |
Are you loading the |
Oh yes - sorry... I'm trying to use the The problem seems to only occur, if you run |
I have done a "quick" pass on this with Node 19 and the refactoring required and using it within another project as a module and it works, but it is no longer backward compatible with Node.js 18. Also some of the libraries start to generate issues between commonjs and ESmodules... I think this would require a line in the sand and conversion to Node.js 19 and ESmodule for the whole library to make the work, Not to mention a lot of work to convert the tests into TypeScript as that is also causing issues. I have parked the changes on this branch for now; https://github.com/peter-murray/node-hue-api/tree/esmodule if you get the time to check if that works under your use cases, it would help me to decide if this is a sensible direction. I have to work out what the path forward looks like for the updated library as Hue have started to push towards to the new CLIP v2 version now (although it is still missing some functionality, it brings more features). |
It seems the branch is missing something. All I get when trying to build is this error:
|
Apologies, the .gitignore file excluded the custom type definition I needed to add, please try again now that I have forcibly added it, |
@peter-murray this one builds fine and now it works as Great & thanks! |
@peter-murray I just did a fresh start from scratch using the Here's a detailed STR:
logs this: [email protected] build
> tsc -p tsconfig.json && tsc -p tsconfig_esm.json
src/v3.ts:9:7 - error TS2742: The inferred type of 'v3' cannot be named without a reference to 'node-hue-api/node_modules/@peter-murray/hue-bridge-model/dist/esm/time.js'. This is likely not portable. A type annotation is necessary.
9 const v3 = {
~~
Found 1 error in src/v3.ts:9 Isn't that supposed to work? |
patch for current version to be runnable in esm environment:
|
@mo22 Did you apply the patch to the master-branch (installed via |
@tiptronic to node-hue-api/dist/esm in the master branch installed via npm install |
@mo22 Thanks - just found out it works on the Please allow me 1 question - since you're messing with Hue under NodeJS: Do you know a reliable way finding the Hue bridge outside I tried all kinds of pure Javascript |
I don't understand how to use this esm patch. What do i use in "npm install ..." ? And when installed, do i just do import { v3 } from 'node-hue-api'? I tried to use these two on the dafault npm project: |
To use the #220 (comment) you just have to copy/paste into a new file, for example
Then your build should not have any warning anymore PS: on my config I'm using pnpm and i just had to replace all occurrences of |
Thank you abalam666, However I just had to convert to using cjs withing my esmproject, and will jsut run with that for now. Hopefully project gets picked up and version 5 pushed out of beta with esm working out of the box in the future :) |
I cannot import node-hue-api as ESM module. It would be nice if you can support both, ESM as well as Common Modules.
Thanks.
The text was updated successfully, but these errors were encountered: