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 mount @c8y/client dual package hazard #84

Closed
thomaswinkler opened this issue Apr 7, 2024 · 3 comments · Fixed by #85
Closed

Fix mount @c8y/client dual package hazard #84

thomaswinkler opened this issue Apr 7, 2024 · 3 comments · Fixed by #85

Comments

@thomaswinkler
Copy link
Collaborator

thomaswinkler commented Apr 7, 2024

The mount command does register a provider for FetchClient. In the current configuration, typescript generates the FetchClient import in mount.ts as require(), ngx-components however imports FetchClient with import from resulting in a so called "dual package hazard".

This potential comes from the fact that the pkgInstance created by const pkgInstance = require('pkg') is not the same as the pkgInstance created by import pkgInstance from 'pkg' (or an alternative main path like 'pkg/module'). This is the “dual package hazard,” where two versions of the same package can be loaded within the same runtime environment.

@c8y/client is provided as a single source npm module with different cjs and esm exports. This results in mount with require and ngx-components with import loading 2 different instances. With this, the FetchClient provider registered by mount is not used.

See Node.js Dual Package Hazard doc and Cypress Typescript doc

As a workaround mount is currently implemented as javascript, which is considered a workaround only and should be fixed. Changing typescript configuration results in error loading the plugin in Cypress node runtime. This might require to split plugin and commands to enable different build settings.

Related Cypress issues:

See here for guide on creating single source npm modules.

@thomaswinkler
Copy link
Collaborator Author

Started enabling eslint and typescript refactoring in #83 to prepare possible split of plugin and lib.

@thomaswinkler
Copy link
Collaborator Author

When building with es2020 module setting, the plugin does not load with the following error. See linked Cypress issues in the description.

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for .../digital-twin-manager/cypress.config.ts

There seems to be no fix / workaround for this to be working.

@thomaswinkler thomaswinkler linked a pull request Apr 8, 2024 that will close this issue
@thomaswinkler
Copy link
Collaborator Author

Fixed by #85. Using rollup, the plugin is now prepared to work with Cypress from es2020 build.

thomaswinkler added a commit that referenced this issue Apr 9, 2024
…l-package-hazard

#84: Fix loading plugin in Cypress with es2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant