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

Error [ERR_REQUIRE_ESM]: require() of ES Module - Jellyfin SDK 0.8.1 ESM #167

Open
manuel-rw opened this issue Apr 11, 2023 · 0 comments
Open
Assignees
Labels
bug Something isn't working dependencies Pull requests that update a dependency file

Comments

@manuel-rw
Copy link
Owner

manuel-rw commented Apr 11, 2023

Describe the bug
In the commit https://github.com/jellyfin/jellyfin-sdk-typescript/pull/341/files, the SDK was made to target ES6 properly.
During an automated pull request, that updated from the SDK 0.7.0 to 0.8.1 (#154), the project broke.
According to https://stackoverflow.com/questions/74830166/unable-to-import-esm-module-in-nestjs/75287028#75287028 and nestjs/nest#8736, Nestjs does not support ES modules.
This causes any following Github Actions to fail and not build the image.

I temporarily reverted this in #166 to make the CI pass again.

To Reproduce
Steps to reproduce the behavior:

  1. Upgrade @jellyfin/sdk to 0.8.1 or higher
  2. Run yarn start

Expected behavior
The build and tests are passing.

Actual behaviour:

yarn run v1.22.19
$ nest start
 
E:\jellyfin-discord-music-bot\dist\clients\jellyfin\jellyfin.search.service.js:14
const models_1 = require("@jellyfin/sdk/lib/generated-client/models");
                 ^
Error [ERR_REQUIRE_ESM]: require() of ES Module E:\jellyfin-discord-music-bot\node_modules\@jellyfin\sdk\lib\generated-client\models\index.js from E:\jellyfin-discord-music-bot\dist\clients\jellyfin\jellyfin.search.service.js not supported.
Instead change the require of index.js in E:\jellyfin-discord-music-bot\dist\clients\jellyfin\jellyfin.search.service.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (E:\jellyfin-discord-music-bot\dist\clients\jellyfin\jellyfin.search.service.js:14:18)
    at Object.<anonymous> (E:\jellyfin-discord-music-bot\dist\clients\jellyfin\jellyfin.module.js:14:35)
    at Object.<anonymous> (E:\jellyfin-discord-music-bot\dist\clients\discord\discord.module.js:14:27)
    at Object.<anonymous> (E:\jellyfin-discord-music-bot\dist\app.module.js:19:26)
    at Object.<anonymous> (E:\jellyfin-discord-music-bot\dist\main.js:4:22)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Additional context
It might be possible to work around this with dynamic modules (Stackoverflow issue for context).
The Jellyfin SDK could also be made for commonjs, but that might be a lot of additional work.
I think it's best to keep up with updates and use a workaround, until Nestjs implemented proper handling for ESM.

The ideal solution would be, to use ESM instead. However, the PR in Nestjs has been stale for over 2 years.
I doubt that there will be any progress on it anytime soon. If there should be support for this someday, the asynchronous imports should be reverted.

@manuel-rw manuel-rw added bug Something isn't working dependencies Pull requests that update a dependency file labels Apr 11, 2023
@manuel-rw manuel-rw self-assigned this Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests that update a dependency file
Projects
None yet
Development

No branches or pull requests

1 participant