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

Build and runtime issues on node with ESBuild #60

Closed
dankelleher opened this issue Jun 14, 2023 · 0 comments
Closed

Build and runtime issues on node with ESBuild #60

dankelleher opened this issue Jun 14, 2023 · 0 comments
Assignees

Comments

@dankelleher
Copy link

Describe the bug
ESBuild has issues building this library.

The three issues I am having:

  1. (build time) ../../node_modules/ky-universal/index.js:28:30: ERROR: Top-level await is currently not supported with the "cjs" output format
    Related to Lack of CommonJS support #49 (comment)

  2. (runtime) TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received undefined (tracked this down to an issue in web-workers

  3. (runtime Runtime.ImportModuleError: Error: Cannot find module './fetch.node'

To Reproduce
First issue

  1. Install esbuild (yarn add -D esbuild)
  2. Install [email protected]
  3. Create the following file:

src/index.ts

import { auth } from '@iden3/js-iden3-auth';

export const login = async () => {
    return auth.createAuthorizationRequestWithMessage("foo", "bar", "baz", "https://localhost:3000")
};

4 Attempt to build using `yarn esbuild src/index.ts --bundle --outfile=out.js --platform=node

I get:

$ /Users/daniel/code/civicteam/polypass/node_modules/.bin/esbuild src/index.ts --bundle --outfile=out.js --platform=node
✘ [ERROR] Top-level await is currently not supported with the "cjs" output format

I can hack around this by going into node_modules/@digitalbazaar/http-client/dist/cjs/index.cjs and replacing the import of ky-universal with ky.

Building then works, but I get the other two issues at runtime. I don't think they are related to ky-universal

Expected behavior
Building should work and the createAuthorizationRequestWithMessage function should execute at runtime, resulting in a login JSON

Screenshots
If applicable, add screenshots to help explain your problem.

** Environment info (please complete the following information):**

  • Mac OS
  • Node 18-17
  • Package version 1.0.0-beta.7
  • Build cjs

Additional context
I first experienced this using serverless with AWS lambda. Steps to reproduce that:

  • npx serverless create --template aws-nodejs-typescript myapp
  • cd myapp
  • yarn install @iden3/js-iden3-auth

then you can add the same code to the file src/functions/hello/handler.ts
then call
yarn serverless invoke local --function hello

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

4 participants