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

The package may have incorrect main/module/exports specified in its package.json: Missing "." #15405

Closed
7 tasks done
jmsm412 opened this issue Dec 21, 2023 · 3 comments
Closed
7 tasks done

Comments

@jmsm412
Copy link

jmsm412 commented Dec 21, 2023

Describe the bug

I've been trying to use the package @alchemy/aa-signers into my Vite app but whenever I try to use an export (in my case Web3AuthSigner) from the package I get the following error:

Failed to resolve entry for package "@alchemy/aa-signers". The package may have incorrect main/module/exports specified in its package.json: Missing "." specifier in "@alchemy/aa-signers" package

I've noticed a closed ticket with this same error message mentioning to check with the publint.dev tool if all of the exports were correct, and they are.
https://publint.dev/@alchemy/aa-signers@1.2.2

aa-signers documentation also mentions the alternative import "@alchemy/aa-signers/web3auth" that's also not being recognized as valid, in this case I get this error
[plugin:vite:import-analysis] Failed to resolve import "@alchemy/aa-signers/web3auth" from "src/hooks/useConnectUser.tsx". Does the file exist?

Reproduction

https://stackblitz.com/edit/vitejs-vite-thymym

Steps to reproduce

No response

System Info

System:
    OS: macOS 13.0
    CPU: (8) arm64 Apple M1
    Memory: 1.40 GB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 21.2.0 - ~/.nvm/versions/node/v21.2.0/bin/node
    Yarn: 1.22.21 - ~/.nvm/versions/node/v21.2.0/bin/yarn
    npm: 10.2.3 - ~/.nvm/versions/node/v21.2.0/bin/npm
  Browsers:
    Chrome: 120.0.6099.109
    Safari: 16.1
  npmPackages:
    @vitejs/plugin-react: ^4.2.0 => 4.2.1 
    vite: ^5.0.7 => 5.0.10

Used Package Manager

npm

Logs

No response

Validations

Copy link

stackblitz bot commented Dec 21, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@XiSenao
Copy link
Collaborator

XiSenao commented Dec 22, 2023

It may be that thepackage.json module of @alchemy/aa-signers is configured with an exports field, but does not provide a "." in the exports field. Causing the resolve.exports to be unable to find the entry point and report an error.

The exports field has the highest priority. If exports is configured in package.json but not specified with ".", an error will occur because the entry point cannot be determined. I think this is an improper practice in itself, and it's not Vite's problem.

"exports": {
  ".": {
    "import": "./dist/esm/index.js",
    "require": "./dist/cjs/index.js"
   }
 }

@bluwy
Copy link
Member

bluwy commented Dec 22, 2023

Yeah, what @XiSenao mentioned above is correct. Perhaps publint could add a check for this case.

aa-signers documentation also mentions the alternative import "@alchemy/aa-signers/web3auth" that's also not being recognized as valid, in this case I get this error
[plugin:vite:import-analysis] Failed to resolve import "@alchemy/aa-signers/web3auth" from "src/hooks/useConnectUser.tsx". Does the file exist?

I tried this in the repro, and it seems to be working for me. I wrote the import like this:

import {Web3AuthSigner} from '@alchemy/aa-signers/web3auth';

But then, I now got a runtime browser error of ReferenceError: Can't find variable: global, but that's a different issue which I think you can find around the web too. global doesn't exist in browsers.

I'll close this issue for now as it seems to be a library packaging error, but feel free to follow up with any questions.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Dec 22, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jan 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants