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

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

Closed
DercilioFontes opened this issue Nov 28, 2024 · 5 comments
Closed
Assignees

Comments

@DercilioFontes
Copy link

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/[email protected]

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"
  • OS & Device: macOS 15.1.1
  • Node 22

Is there any additional information?

@DercilioFontes
Copy link
Author

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
Copy link
Contributor

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

@mgamis-msft
Copy link
Contributor

@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
Copy link
Author

Hi @mgamis-msft

Sure.

  • tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "module": "ESNext",
    "skipLibCheck": true,
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "strict": true,
    "noUnusedLocals": true,
    "noFallthroughCasesInSwitch": true,
    "sourceMap": true,
    "types": ["vitest/globals"]
  },
  "include": ["src", "types", "types/i18next.d.ts"],
  "references": [{ "path": "./tsconfig.node.json" }]
}
  • tsconfig.node.json
{
  "compilerOptions": {
    "composite": true,
    "skipLibCheck": true,
    "module": "ESNext",
    "moduleResolution": "bundler",
    "allowSyntheticDefaultImports": true
  },
  "include": ["vite.config.ts"]
}

@DercilioFontes
Copy link
Author

Hi @mgamis-msft

After updating to "vite": "^6.0.2" and "vitest": "^2.1.8" the issue no longer occurs.

I'm closing the issue. Thank you for your attention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants