matallui / artico

Artico - WebRTC made simple
https://artico.dev
MIT License
33 stars 3 forks source link

Error [ERR_REQUIRE_ESM]: require() of ES Module #16

Closed jorbo closed 3 days ago

jorbo commented 2 months ago

I am running into an issue trying to create a simple test with your package.

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/jordan/git/generic/project/prototypes/full-stack/electron/utils/artico-test/node_modules/nanoid/index.js from /home/jordan/git/generic/project/prototypes/full-stack/electron/utils/artico-test/node_modules/@rtco/client/build/index.js not supported.
Instead change the require of /home/jordan/git/generic/project/prototypes/full-stack/electron/utils/artico-test/node_modules/nanoid/index.js in /home/jordan/git/generic/project/prototypes/full-stack/electron/utils/artico-test/node_modules/@rtco/client/build/index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/home/jordan/git/generic/project/prototypes/full-stack/electron/utils/artico-test/node_modules/@rtco/client/build/index.js:1:2065) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v20.11.1

Here is my package.json

{
  "name": "artico-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "test": "tsc && node ./build/src/index.js"
  },
  "dependencies": {
    "@rtco/client": "^0.2.11"
  },
  "devDependencies": {
    "@types/jasmine": "^4.3.6",
    "@types/jest": "^29.5.5",
    "asar": "^3.1.0",
    "electron": "^18.0.4",
    "electron-builder": "^23.0.2",
    "electron-rebuild": "^3.2.3",
    "jasmine": "^4.5.0",
    "nodemon": "^3.0.1",
    "patch-package": "^6.4.7",
    "pm2": "^5.2.0",
    "ts-node": "^10.9.1",
    "ts-node-dev": "^1.1.8",
    "typescript": "~5.5.3"
  },
  "author": "",
  "license": "ISC"
}

and my tsconfig.json

 {
  "compileOnSave": true,
  "include": ["./src/**/*", "test-runner/*.ts", "./capacitor.config.ts", "./capacitor.config.js"],
  "compilerOptions": {
    "outDir": "./build",
    "importHelpers": true,
    "target": "es2020",
    "module": "CommonJS",
    "moduleResolution": "Node",
    "strictNullChecks": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "typeRoots": ["./node_modules/@types"],
    "allowJs": true,
    "rootDir": "."
  },
  "exclude": [
    "./src/server/www",
    "./src/server/www/**/*",
    "./src/server/db",
    "./src/server/db/**/*",
  ]
}

Here is my index.ts


import { Artico, type Call } from "@rtco/client";
;

const rtco = new Artico();

rtco.on("open", (id: string) => {
  // We're now connected to the signaling server.
  // `id` refers to the unique ID that is currently assigned to this peer, so remote peers can connect to us.
  console.log("Connected to signaling server with peer ID:", id);
});

rtco.on("close", () => {
  console.log("Connection to signaling server is now closed.");
});

rtco.on("error", (err) => {
  console.log("Artico error:", err);
});

rtco.on("call", (call: Call) => {
  // The calling peer can link any metadata object to a call.
  const { metadata } = call;
  const remotePeerName = JSON.parse(metadata!).name;

  console.log(`Call from ${remotePeerName}...`);

  // Answer the call.
  call.answer();

  call.on("stream", (stream, metadata) => {
    // Stream was added by remote peer, so display it somehow.
    // `metadata` can be appended by the remote peer when adding the stream.
  });
});```
matallui commented 1 month ago

@jorbo can you point me to this test repo so I can clone and test it out? And also provide instructions on how to reproduce the issue? Thanks!