Repository: ProvableHQ/sdk (language: rust)

Issue:
[Bug] Having error with latest create-leo-app
## 🐛 Bug Report

<!--
    What's the bug in the Aleo SDK that you found?
    How serious is this bug and what is affected?

    To report a security issue in the Aleo SDK, please email security@aleo.org.
-->

Follow guide to run `create-leo-app` but encounter error during run dev. Noticed the update of `@provablehq/sdk` to `0.7.0`. Fallback to `0.6.13` works.

## Steps to Reproduce

<!-- How do I reproduce this issue in the Aleo SDK? -->

#### Code snippet to reproduce

```
npm create leo-app@latest
cd aleo-project
npm install
npm run dev
```

#### Stack trace & error message

```bash
Failed to resolve import "core-js/proposals/json-parse-with-source.js" from "node_modules/@provablehq/sdk/dist/testnet/browser.js?v=cc7fe778". Does the file exist?
6:05:15 PM [vite] Internal server error: Failed to resolve import "core-js/proposals/json-parse-with-source.js" from "node_modules/@provablehq/sdk/dist/testnet/browser.js?v=cc7fe778". Does the file exist?
  Plugin: vite:import-analysis
  File: /aleo-project/node_modules/@provablehq/sdk/dist/testnet/browser.js?v=cc7fe778:1:9
  1  |  import 'core-js/proposals/json-parse-with-source.js';
     |          ^
  2  |  import { ViewKey, Address, PrivateKeyCiphertext, PrivateKey, RecordCiphertext, Program, Transaction, ProvingKey, VerifyingKey, ProgramManager as ProgramManager$1, RecordPlaintext, verifyFunctionExecution, Metadata } from '@provablehq/wasm/testnet.js';
  3  |  export { Address, ExecutionResponse, Field, Execution as FunctionExecution, OfflineQuery, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager as ProgramManagerBase, ProvingKey, RecordCiphertext, RecordPlaintext, Signature, Transaction, VerifyingKey, ViewKey, initThreadPool, verifyFunctionExecution } from '@provablehq/wasm/testnet.js';
```

## Expected Behavior

<!--
    What was supposed to happen in the Aleo SDK?
    What happened instead?
-->

Able to run dev without errors

## Your Environment

- create-leo-app Version - 0.7.3
- Provable SDK Version - 0.7.0
- Computer OS - MacOS Sequoia 15.0.1



Discussion / hints:
Same issue
Same issue
For context, this error only occurs when I run `npm create leo-app@latest` and select `Node.js` as the framework
@Pauan any idea why this might be?
This issue also occurs when running `npm create leo-app@latest` with `React`, and then building the project using `npm run build`.
For the React option, I was able to get `npm run build` working after installing `core-js`.
For the Typescript option, I get this error when I get this error
```
> npm run dev
npm error Missing script: "dev"
npm error
npm error To see a list of scripts, run:
npm error   npm run
npm error A complete log of this run can be found in: /Users/pranav/.npm/_logs/2024-11-27T16_16_51_580Z-debug-0.log
```
> For the React option, I was able to get `npm run build` working after installing `core-js`. For the Typescript option, I get this error when I get this error
> 
> ```
> > npm run dev
> npm error Missing script: "dev"
> npm error
> npm error To see a list of scripts, run:
> npm error   npm run
> npm error A complete log of this run can be found in: /Users/pranav/.npm/_logs/2024-11-27T16_16_51_580Z-debug-0.log
> ```

There's some errors printed in console and all functions from `worker.js` doesn't work even after installed `core-js` package for React option
<img width="586" alt="Screenshot 2024-11-28 at 12 54 19 AM" src="https://github.com/user-attachments/assets/bc24efae-45e7-4ece-bbf3-c4388391c31d">

Thanks for the report, this seems to be caused by #925, I think we just need to update the examples.

Fix patch:
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 0f1b52640..4d342f90b 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -99,7 +99,7 @@ jobs:
       - run:
           working_directory: create-leo-app/template-node
           command: |
-            yarn start
+            yarn dev
 
   template-node-ts:
     executor: rust-node
@@ -108,7 +108,7 @@ jobs:
       - run:
           working_directory: create-leo-app/template-node-ts
           command: |
-            yarn start
+            yarn dev
 
   template-extension:
     executor: rust-node
diff --git a/create-leo-app/template-node-ts/package.json b/create-leo-app/template-node-ts/package.json
index be36c97a3..6c3e3df2f 100644
--- a/create-leo-app/template-node-ts/package.json
+++ b/create-leo-app/template-node-ts/package.json
@@ -5,7 +5,7 @@
   "type": "module",
   "scripts": {
     "build": "rimraf dist/js && rollup --config",
-    "start": "npm run build && node dist/index.js"
+    "dev": "npm run build && node dist/index.js"
   },
   "dependencies": {
     "@provablehq/sdk": "^0.7.0"
diff --git a/create-leo-app/template-node/package.json b/create-leo-app/template-node/package.json
index 0334fe2ba..a37b987a9 100644
--- a/create-leo-app/template-node/package.json
+++ b/create-leo-app/template-node/package.json
@@ -4,7 +4,7 @@
   "version": "0.0.0",
   "type": "module",
   "scripts": {
-    "start": "node index.js"
+    "dev": "node index.js"
   },
   "dependencies": {
     "@provablehq/sdk": "^0.7.0"
diff --git a/create-leo-app/template-offline-public-transaction-ts/package.json b/create-leo-app/template-offline-public-transaction-ts/package.json
index 7d836216e..663095c84 100644
--- a/create-leo-app/template-offline-public-transaction-ts/package.json
+++ b/create-leo-app/template-offline-public-transaction-ts/package.json
@@ -5,7 +5,7 @@
   "type": "module",
   "scripts": {
     "build": "rimraf dist/js && rollup --config",
-    "start": "npm run build && node dist/index.js"
+    "dev": "npm run build && node dist/index.js"
   },
   "dependencies": {
     "@provablehq/sdk": "^0.7.0"
diff --git a/sdk/package.json b/sdk/package.json
index bebc2b24a..52f55fd1a 100644
--- a/sdk/package.json
+++ b/sdk/package.json
@@ -50,7 +50,8 @@
     "@provablehq/wasm": "^0.7.0",
     "comlink": "^4.4.1",
     "mime": "^3.0.0",
-    "sync-request": "^6.1.0"
+    "sync-request": "^6.1.0",
+    "core-js": "^3.38.1"
   },
   "devDependencies": {
     "@rollup/plugin-replace": "^5.0.5",
@@ -63,7 +64,6 @@
     "better-docs": "^2.7.2",
     "chai": "^5.1.1",
     "clean-jsdoc-theme": "^4.1.8",
-    "core-js": "^3.38.1",
     "cpr": "^3.0.1",
     "eslint": "^8.26.0",
     "eslint-config-prettier": "^8.5.0",
diff --git a/sdk/src/polyfill/worker.ts b/sdk/src/polyfill/worker.ts
index 8f979db29..7e05d61a9 100644
--- a/sdk/src/polyfill/worker.ts
+++ b/sdk/src/polyfill/worker.ts
@@ -32,10 +32,11 @@ globalThis.Worker = class Worker extends EventTarget {
         }
 
         const code = `
-            const { workerData } = require("node:worker_threads");
-
-            import(workerData.polyfill)
-                .then(() => import(workerData.url))
+            import("node:worker_threads")
+                .then(({ workerData }) => {
+                    return import(workerData.polyfill)
+                        .then(() => import(workerData.url))
+                })
                 .catch((e) => {
                     // TODO maybe it should send a message to the parent?
                     console.error(e.stack);


Test patch: