Skip to content
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

fix: registry importModule function #3984

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

inglkruiz
Copy link

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Proposed changes

Use parsedModule.module instead of module, module contains the version installed, therefore importing the module results in an error because the folder does not exists in node_modules. See screenshot.

image

Bug introduced here > #3645

Checklist

  • I have read the contribution guidelines
  • For non-bugfix PRs, I have discussed this change on the forum/slack team.
  • I have run grunt to verify the unit tests pass
  • I have added suitable unit tests to cover the new/changed functionality

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Dec 12, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: inglkruiz / name: LuisK Ruiz (80cf63d6576518bac6a5602c64335ad3460f982c)

@inglkruiz inglkruiz force-pushed the fix/registry-import-module branch 2 times, most recently from 80cf63d to 88d1648 Compare December 12, 2022 13:24
Use parsedModule.module for modulePath

Signed-off-by: inglkruiz <12603425+inglkruiz@users.noreply.github.com>
@inglkruiz
Copy link
Author

@knolleary Hi, could you review this PR? sorry for bothering you.

@knolleary
Copy link
Member

Hi @inglkruiz

Sorry for the delay. It wasn't immediately obvious what this PR was fixing, because loading external modules was working fine here. I see now it occurs if you specify a version as part of the module name in the Function node - ipfs-http-client@56.0.3.

Once I understood what it was fixing, it was much clearer to review.

@coveralls
Copy link

Coverage Status

Coverage: 68.257% (-0.0%) from 68.257% when pulling 04b36e7 on inglkruiz:fix/registry-import-module into 113d42e on node-red:master.

@inglkruiz
Copy link
Author

@knolleary Thanks for paying attention to it. I have one more question, the package I'm using ipfs-http-client has migrated to ESM and I'm trying to making it work in NodeRed. One of the contributors suggested this > ipfs/js-ipfs#4265 (comment)

@inglkruiz
Copy link
Author

I forgot to ask, do you think that could work? I understand he's suggesting us to remove const modulePath = createRequire(moduleDir) and use only the dynamic import function.

@knolleary
Copy link
Member

The problem is ESM is a mess. There is no one-size-fits-all solution if you need to load any module without knowing ahead of time what flavour of ESM/CJS, what settings they may or may not have included in their package.json and a million other bits of incompatibility between the different module types.

It's fine if you're writing the code directly, as you can write whatever is needed for the given module. But we have to try to handle everything in Node-RED.

The code we have today came as a result of testing lots of different ESM and CJS modules to try to find something that works somewhat consistently for the set of modules we were testing with.

Any changes to this code will need testing against lots of different modules to ensure absolutely no changes in behaviour for existing users. My fear is this becomes a case of 'fix it for module A, break it for module B'.

@inglkruiz
Copy link
Author

I understand, the situation is quite cumbersome. If you could list what packages you have tested I think I could try to make it work covering more cases and automating some tests. Just offering some help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants