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

Named export '__awaiter' not found #487

Closed
KeyboardDabbler opened this issue May 6, 2023 · 10 comments · Fixed by #712
Closed

Named export '__awaiter' not found #487

KeyboardDabbler opened this issue May 6, 2023 · 10 comments · Fixed by #712
Labels
enhancement New feature or request

Comments

@KeyboardDabbler
Copy link

KeyboardDabbler commented May 6, 2023

I have started a project built on nuxt 3.3.1, added the @jellyfin/sdk library to handle user Auth and future api requests.
Has anyone had any experience using this stack, is the below a bug or a error on my side?
The login end point authenticateUserByName() is working and in response giving me the AccessToken. However there's an issue with specifically, the awaiter function in this library is not working properly with Nuxt.
As a result, i have had to manually make changes to the Node.js module files in order to get the library to work.

[Vue Router warn]: uncaught error during route navigation:                                                                               17:02:02
file:///C:/Users/keyboardDabbler/Desktop/gbstreams/node_modules/.pnpm/@[email protected][email protected]/node_modules/@jellyfin/sdk/lib/generated-client/common.js:1
import { __awaiter } from '../node_modules/tslib/tslib.es6.js';
         ^^^^^^^^^
SyntaxError: Named export '__awaiter' not found. The requested module '../node_modules/tslib/tslib.es6.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '../node_modules/tslib/tslib.es6.js';
const { __awaiter } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:181:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at async ViteNodeRunner.interopedImport (file:///C:/Users/keyboardDabbler/Desktop/gbstreams/node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:327:28)
    at async ViteNodeRunner.directRequest (file:///C:/Users/keyboardDabbler/Desktop/gbstreams/node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:227:24)
    at async ViteNodeRunner.cachedRequest (file:///C:/Users/keyboardDabbler/Desktop/gbstreams/node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:159:14)
    at async ViteNodeRunner.dependencyRequest (file:///C:/Users/keyboardDabbler/Desktop/gbstreams/node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:207:14)
    at async C:\Users\keyboardDabbler\Desktop\gbstreams\utils\jellyfinSdk.ts:1:31
    at async ViteNodeRunner.directRequest (file:///C:/Users/keyboardDabbler/Desktop/gbstreams/node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:315:5)
[Vue Router warn]: uncaught error during route navigation:                                                                               17:02:02
file:///C:/Users/keyboardDabbler/Desktop/gbstreams/node_modules/.pnpm/@[email protected][email protected]/node_modules/@jellyfin/sdk/lib/generated-client/common.js:1
import { __awaiter } from '../node_modules/tslib/tslib.es6.js';
         ^^^^^^^^^
SyntaxError: Named export '__awaiter' not found. The requested module '../node_modules/tslib/tslib.es6.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '../node_modules/tslib/tslib.es6.js';
const { __awaiter } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:181:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at async ViteNodeRunner.interopedImport (file:///C:/Users/keyboardDabbler/Desktop/gbstreams/node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:327:28)
    at async ViteNodeRunner.directRequest (file:///C:/Users/keyboardDabbler/Desktop/gbstreams/node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:227:24)
    at async ViteNodeRunner.cachedRequest (file:///C:/Users/keyboardDabbler/Desktop/gbstreams/node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:159:14)
    at async ViteNodeRunner.dependencyRequest (file:///C:/Users/keyboardDabbler/Desktop/gbstreams/node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:207:14)
    at async C:\Users\keyboardDabbler\Desktop\gbstreams\utils\jellyfinSdk.ts:1:31
    at async ViteNodeRunner.directRequest (file:///C:/Users/keyboardDabbler/Desktop/gbstreams/node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:315:5)
[Vue Router warn]: uncaught error during route navigation:                                                                               17:02:02
file:///C:/Users/keyboardDabbler/Desktop/gbstreams/node_modules/.pnpm/@[email protected][email protected]/node_modules/@jellyfin/sdk/lib/generated-client/common.js:1
import { __awaiter } from '../node_modules/tslib/tslib.es6.js';
         ^^^^^^^^^
SyntaxError: Named export '__awaiter' not found. The requested module '../node_modules/tslib/tslib.es6.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '../node_modules/tslib/tslib.es6.js';
const { __awaiter } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:181:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at async ViteNodeRunner.interopedImport (file:///C:/Users/keyboardDabbler/Desktop/gbstreams/node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:327:28)
    at async ViteNodeRunner.directRequest (file:///C:/Users/keyboardDabbler/Desktop/gbstreams/node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:227:24)
    at async ViteNodeRunner.cachedRequest (file:///C:/Users/keyboardDabbler/Desktop/gbstreams/node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:159:14)
    at async ViteNodeRunner.dependencyRequest (file:///C:/Users/keyboardDabbler/Desktop/gbstreams/node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:207:14)
    at async C:\Users\keyboardDabbler\Desktop\gbstreams\utils\jellyfinSdk.ts:1:31
    at async ViteNodeRunner.directRequest (file:///C:/Users/keyboardDabbler/Desktop/gbstreams/node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:315:5)
    ```
@KeyboardDabbler
Copy link
Author

I found some information in the nuxt documentation link. I have overcome the error for now without manually making changes to the module files.

I will reference the following
If you encounter these errors, the issue is almost certainly with the upstream library. They need to fix their library to support being imported by Node.

@manuel-rw
Copy link

Just for the record, #341 caused this error.
I have it in all of my projects... Apparently, neither Nestjs nor Nextjs support es modules properly.
Because there weren't too many Jellyfin API changes, I have been procrastinating finding a solution for it, but you'll probably have to experiment with TS targets and es modules. If I find anything, I'll post it here.

Conversation via Element:
image

@manuel-rw
Copy link

@Meierschlumpf helped me with ajnart/homarr#1016 . Now working again for our project.

@conner-replogle
Copy link

I'm having this issue with SvelteKit is there any fix for it?

@szethh

This comment has been minimized.

@thornbill
Copy link
Member

As I commented previously this library only ships as an ES module. If you are working in an ecosystem that does not support ES modules, you may need to have a build step to convert the library to a compatible module format.

I am curious if distributing *.mjs files would help in some of these cases, but someone would have to test that.

@isaac-mcfadyen
Copy link

isaac-mcfadyen commented Feb 21, 2024

If you are working in an ecosystem that does not support ES modules, you may need to have a build step to convert the library to a compatible module format.

According to the SvelteKit docs, it seems they do support ESM but only when "type": "module" is indicated in the package.json, which it doesn't seem to be for tslib (the import that's failing):
https://kit.svelte.dev/docs/faq#how-do-i-fix-the-error-i-m-getting-trying-to-include-a-package
https://github.com/microsoft/tslib/blob/main/package.json

It doesn't seem tslib wants to change this either for backwards compatibility reasons:
microsoft/tslib#180

In dev mode, Vite actually suggests importing using the following. I wonder if this would work as a workaround, but I'm not exactly sure how to change it given that the import for tslib seems to be autogenerated and not actually written this way in the source files.

import pkg from '../node_modules/tslib/tslib.es6.js';
const { __awaiter } = pkg;

@jordanf97
Copy link

Any updates on this? I've not found a way around it.

From my perspective the Jellyfin SDK is being published as an ES module with a transient dependancy which is a CJS module. (at least this is how Vite sees it).

tslib seems to have no intention of bundling their library as an ES module for compatibility reasons which leaves this SDK in an unusable state for myself and others.

I'm just going to either not use the SDK or copy the source files across directly but obviously neither of these solutions are ideal

@jordanf97
Copy link

For what it's worth I found a middle ground solution which is good-enough for me it's probably dumb but hopefully someone else might find it useful too.

I created a package patch where I defined the tslib package as module by creating a package.json file within @jellyfin/sdk/lib/node_modules/tslib/.

The contents of the patch file:

new file mode 100644
index 0000000..1632c2c
--- /dev/null
+++ b/node_modules/@jellyfin/sdk/lib/node_modules/tslib/package.json
@@ -0,0 +1 @@
+{"type": "module"}
\ No newline at end of file

@thornbill thornbill added the enhancement New feature or request label Jun 3, 2024
@thornbill
Copy link
Member

thornbill commented Jun 3, 2024

This should be fixed in the next release, but if you would like to confirm before then, you can test the latest unstable tag.

Update: I've confirmed the issue is fixed for jest in jellyfin-expo at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants