endojs / endo

Endo is a distributed secure JavaScript sandbox, based on SES
Apache License 2.0
801 stars 71 forks source link

App scaffolded with create-cosmos-app cannot call lockdown successfully #2033

Open samsiegart opened 7 months ago

samsiegart commented 7 months ago

Describe the bug

As shown in https://github.com/agoric-labs/hardened-create-cosmos-app, when I try using create-cosmos-app to make a cosmos app (which runs on Next.js), I cannot successfully invoke lockdown and run the app.

Error Details:

See the README of the example repo for error details.

Steps to reproduce

  1. Clone https://github.com/agoric-labs/hardened-create-cosmos-app
  2. yarn && yarn dev to install deps and run locally
  3. Load the url outputted by yarn dev
  4. Observe the error

Expected behavior

lockdown can be invoked in the top-level of the application without error.

Platform environment

Additional context

Create-cosmos-app is a tool for scaffolding cosmos apps with Next.js. It would be beneficial to be able to use SES and Endo APIs in apps built using this tool. The error is perhaps more general to Next.js as a whole, but this tool is of particular interest.

Screenshots

See https://github.com/agoric-labs/hardened-create-cosmos-app

kriskowal commented 7 months ago

This smells like a CommonJS interop issue and I would like to summon @naugtur, if we can borrow his eyes.

kriskowal commented 7 months ago

@samsiegart Capturing the error in the description will help us diagnose.

samsiegart commented 7 months ago

@samsiegart Capturing the error in the description will help us diagnose.

There's a screenshot and two stack traces in the example repo's README. I've updated the description here to point it out more explicitly

samsiegart commented 7 months ago

Oh, it's private, I should make it public

Edit: done

erights commented 7 months ago

@kriskowal , I've assigned it to the two of us.

erights commented 7 months ago

@naugtur , you too ;)

LuqiPan commented 6 months ago

Another data point- shouldn't be a surprise given I'm using the same create-cosmos-app, just with a slightly different template: I tried to initialize an NFT example with create-cosmos-app --name hardened-nft-example --example nft and I got the same error as @samsiegart, see https://github.com/agoric-labs/hardened-nft-example?tab=readme-ov-file#bug-report

erights commented 6 months ago

Reproduced locally! Thanks for the clear and simple instructions.

erights commented 6 months ago

Yeah, @naugtur @kriskowal , it is all about the cjs loader. I will definitely need your help looking at this. It was easy to reproduce locally, so could you have a look? If the bug is interesting, perhaps we could discuss it at the upcoming endo meeting?

erights commented 6 months ago

Actually, this seems kinda urgent for us. Could we meet tomorrow after you've taken a first look? I am free tomorrow anytime after 2pm Pacific.

kumavis commented 6 months ago

@tgrecojs you mentioned on the call you might be familiar with this issue

tgrecojs commented 6 months ago

I just took a moment to spin up an example repo which integrates @endo/init into a next.js application. This code can be found here - https://github.com/tgrecojs/nextjs-with-endo-init

Pasting the contents of the README file from that repository below. @samsiegart let me know if this helps as all. One more thing I want to note - I think your repo may be using a version of past next.js. FWIW I have wired up past versions to work with endo so I don't believe that is the issue here but I'm not entirely sure.

README.md

Next.js X @endo/init

View this incredibly rich and interactive demo here - https://hardened-nextjs-repo.vercel.app/.

This repository demonstrates the integration of Endo and Knit within a Next.js application.

Below you can view contents of the project's _document.js file.

import { Html, Head, Main, NextScript } from "next/document";
import Script from "next/script";

export default function Document() {
  return (
    <Html>
      <Head />
      <body>
        <Main />
        <NextScript />
        <Script
          async
          type="module"
          src="https://esm.sh/@endo/init@1.0.2"
          strategy="beforeInteractive"
        />
      </body>
    </Html>
  );
}

The key component within this file is the Next.js specific Githubissues.

  • Githubissues is a development platform for aggregating issues.