Azure / communication-ui-library

UI Library for Azure Communication Services helps developers build communication applications with ease. From turn-key composites to UI components that can be composited together.
https://aka.ms/acsstorybook
MIT License
175 stars 71 forks source link

Vitest Failed to resolve entry for package "@azure/communication-react" #5451

Open DercilioFontes opened 3 days ago

DercilioFontes commented 3 days ago

Describe the bug; what happened? I updated the "@azure/communication-react" to version 1.21.0. Before, tests worked fine with version 1.18.1. However, I also updated Vite to v6 and Vitest to 2.1.6.

When trying to run the tests with Vitest, I get this error:

7:24:47 AM [vite] (client) Pre-transform error: Failed to resolve entry for package "@azure/communication-react". The package may have incorrect main/module/exports specified in its package.json: No known conditions for "." specifier in "@azure/communication-react" package
  Plugin: vite:import-analysis
  File: /Users/trycycle-dercilio/repos.nosync/elm/src/hooks/useCreateChatAdapter.ts:5:85
  1  |  import { useEffect, useMemo, useState } from "react";
  2  |  import { createAzureCommunicationChatAdapter, fromFlatCommunicationIdentifier } from "@azure/communication-react";
     |                                                                                        ^

The build and app works fine.

I couldn't figure out how to solve it. Could it be a problem with how the package package.json is configured? I checked the package in this tool, and it suggests some changes. Could it help? https://publint.dev/@azure/communication-react@1.21.0

However, it could also be some configuration with Vitest and Vite to fix it. Could you guys give some advice about that?

What are the steps to reproduce the issue? Probably a new project with Vite, Vitest and @azure/communication-react to test it.

What behavior did you expect? To resolve the import properly

If applicable, provide screenshots:

In what environment did you see the issue?

"@azure/communication-chat": "^1.5.4",
"@azure/communication-common": "^2.3.1",
"@azure/communication-react": "^1.21.0",
"react": "^18.3.1",
"typescript": "^5.7.2",
"vite": "^6.0.1",
"vitest": "^2.1.6"

Is there any additional information?

DercilioFontes commented 3 days ago

I could make it work with this Vitest config pointing to cjs.

    test: {
      globals: true,
      environment: 'jsdom',
      setupFiles: 'src/setupTests.ts',
      alias: {
        '@azure/communication-react': path.resolve(
          __dirname,
          'node_modules/@azure/communication-react/dist/dist-cjs/communication-react/index.js',
        ),
      },
    },
  });
mgamis-msft commented 3 days ago

Hi @DercilioFontes, thanks for filing this issue. I will have a discussion with my team about this and let you know.

mgamis-msft commented 2 days ago

@DercilioFontes Could you share your typescript config? You need to be using certain resolver to pick up the entry points. Just to note, VItest seems to work better with node.js environment

DercilioFontes commented 2 days ago

Hi @mgamis-msft

Sure.