spacebudz / lucid

Lucid is a library, which allows you to create Cardano transactions and off-chain code for your Plutus contracts in JavaScript, Deno and Node.js.
https://lucid.spacebudz.io
MIT License
336 stars 133 forks source link

No "exports" main defined in package.json #229

Closed iftieaq closed 9 months ago

iftieaq commented 9 months ago

I have been trying to run Lucid on my Nest.js (Nodejs framework) backend written in typescript but it seems running to an error

Error: No "exports" main defined in /.../node_modules/lucid-cardano/package.json
    at new NodeError (node:internal/errors:387:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:365:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:589:7)
    at resolveExports (node:internal/modules/cjs/loader:522:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:562:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:971:27)
    at Function.Module._load (node:internal/modules/cjs/loader:833:27)
    at Module.require (node:internal/modules/cjs/loader:1057:19)
    at require (node:internal/modules/cjs/helpers:103:18)

My tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "ES2021",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false,
    "moduleResolution": "node",
    "allowJs": true,
    "esModuleInterop": true,
    "strict": false
  }
}

Any idea how I can get this to working?

egarkavy commented 7 months ago

@iftieaq have you figured out how to make it working? The only way I found is to make a dynamic import but we loose all possible intellisense features const L = (eval('import('lucid-cardano')') as Promise<any>);

iftieaq commented 7 months ago

@iftieaq have you figured out how to make it working? The only way I found is to make a dynamic import but we loose all possible intellisense features const L = (eval('import('lucid-cardano')') as Promise<any>);

The issue was Lucid is written as an ES module. If your project is commonjs, it will not work and throw this export warning. You will have to convert your project from commonjs to ES module in order for lucid to work (please proceed with CAUTION if you would like to do so).