Error while importing NylasSessions from @nylas/identity

Hello,

I am trying to upgrade Nylas from v2 to v3 in my already existing React-Javascript repository. Currently I am trying to implement the Nylas Scheduler Editor. I am following the react sample provided in Github.

As shown in the sample project, I am importing { NylasSessions } from @nylas/identity package.
I am using the latest version of the package.
But I am getting this error while running the application:
Attempted import error: ‘@nylas/identity’ does not contain a default export (imported as ‘NylasSessions’)

How can I resolve this error?
I have added screenshot of the both code and the error above.
Thanks a lot in advance for the help.

Hello @koustav I already asked, so will get back to you :slight_smile:

@koustav The import should be like this

import { NylasSessions } from '@nylas/identity';

i have tried with that as well. that’s what i had started with as per the github samples. still no luck. same error. i was just playing around with the import statement.

@koustav I just tried it out and it works fine for me :thinking: I’m not by any means a Node developer…so I just download the source code, run npm install and then npm run dev…all good for me…

I’m using Node v18.20.3

hello @Blag, the source code works fine for me as well but fails when I am using the same code in my React-Javascript repository. Here are some details that might help:
Versions:
@nylas/identity”: “latest”,
@nylas/login-component”: “latest”,
@nylas/react”: “latest”,
“react”: “^18.3.1”,

node: v18.20.4

I am not using Vite and my React repository is in Javascript but the Nylas sample code is in Typescript and using Vite.

My import statement:
import { NylasSessions } from ‘@nylas/identity’;

What ever I try, I fail to fix the errors.

Thanks @koustav that will help us to pinpoint where the error is :thinking:

hello @Blag, I have created a small Github repo with the piece of code that is causing issue. Here is the link: GitHub - KoustavFrost/nylas-schedule-editor
I have also mentioned the steps to replicate the error in the README file.
thanks.

Perfect! Thanks @koustav that’s even better :star_struck: Will try it out and I have requested the Scheduler team to test it as well…

@koustav Got an answer and a solution :wink:

I took a look at the repo, and was able to reproduce the error.
The issue with the `@nylas/identity` package is that its **ESM build** 
is missing required file extensions in its internal 
imports (e.g., import './app'; instead of import './app.js';). 
Modern bundlers default to using the ESM version, 
which leads to module resolution errors.**Workaround:**
To avoid these errors, change your import to use the pre-built, 
bundled version from the dist folder:

import { NylasSessions } from '@nylas/identity/dist/nylas-identity.es.js';

This file is fully bundled and avoids the ESM issues.

Why it works in the github sample?

The sample code uses Vite as a bundler. 
Vite is known for being ESM-first, meaning it works well 
with ESM dependencies out-of-the-box, even in strict module 
environments. This is likely why it can resolve the missing 
extensions or imports in `@nylas/identity` without errors.

This will be fixed so no workaround is needed :wink:

1 Like

hey @Blag, thanks for the solution. It worked. :grin:

1 Like