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

ERR_PACKAGE_PATH_NOT_EXPORTED #302

Open
MentatX opened this issue Jul 25, 2024 · 1 comment
Open

ERR_PACKAGE_PATH_NOT_EXPORTED #302

MentatX opened this issue Jul 25, 2024 · 1 comment

Comments

@MentatX
Copy link

MentatX commented Jul 25, 2024

Minimal sample with import:

import { CID } from 'multiformats';

async function main() {
    console.log(CID.parse('QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4'));
}
  
main().catch((error) => {
    console.error(error);
    process.exitCode = 1;
});

Getting:

Error: No "exports" main defined in /home/dag-json-demo/node_modules/multiformats/package.json
    at exportsNotFound (node:internal/modules/esm/resolve:304:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:594:13)
    at resolveExports (node:internal/modules/cjs/loader:590:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:667:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1129:27)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/home/dag-json-demo/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
    at Function.Module._load (node:internal/modules/cjs/loader:984:27)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/home//dag-json-demo/scripts/demo/dag-json.ts:1:1) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Expected behavior:
Import CID

Environment:

@ipld/dag-json v10.2.2,
node v20.12.2
npm 10.5.0
tsx v4.16.2

tsconfig.json

{
  "compilerOptions": {
    "target": "es2020",
    "module": "commonjs",
    "strict": true,
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "outDir": "dist",
    "declaration": true,
    "typeRoots": ["./typechain-types", "./node_modules/@types"],
    "types": ["@nomiclabs/hardhat-ethers"]
  },
  "include": ["./scripts", "./test", "./typechain-types"],
  "files": ["./hardhat.config.ts"]
}

The same result with tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "outDir": "dist",
    "declaration": true,
    "typeRoots": ["./typechain-types", "./node_modules/@types"],
    "types": ["@nomiclabs/hardhat-ethers"]
  },
  "include": ["./scripts", "./test", "./typechain-types"],
  "files": ["./hardhat.config.ts"]
}
@tabcat
Copy link
Contributor

tabcat commented Jul 25, 2024

tsx is looking for package.main to import multiformats but multiformats only uses the package.exports field.

try setting your projects package.type to 'module' so tsx will resolve multiformats using package.exports.

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

No branches or pull requests

2 participants