Skip to content

Conversation

@CapoMK25
Copy link
Collaborator

Brief description

When running npm run start:dev I ran into this issue:

`[8:35:17 PM] Starting compilation in watch mode...

[8:35:26 PM] Found 0 errors. Watching for file changes.

[dotenv@17.2.2] injecting env (0) from .env -- tip: ⚙️  specify custom .env file path with { path: '/custom/path/.env' }
C:\Users\Matias.DESKTOP-2SBTD6B\Desktop\Altzone-Server\dist\gameAnalytics\logFile.service.js:19
const webdav_1 = require("webdav");
                 ^

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\Matias.DESKTOP-2SBTD6B\Desktop\Altzone-Server\node_modules\webdav\dist\node\index.js from C:\Users\Matias.DESKTOP-2SBTD6B\Desktop\Altzone-Server\dist\gameAnalytics\logFile.service.js not supported.
Instead change the require of index.js in C:\Users\Matias.DESKTOP-2SBTD6B\Desktop\Altzone-Server\dist\gameAnalytics\logFile.service.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (C:\Users\Matias.DESKTOP-2SBTD6B\Desktop\Altzone-Server\dist\gameAnalytics\logFile.service.js:19:18) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v20.11.0

Turns out the project doesn't work out of the gate and required extensive tweaking to the source code to bypass this ESM vs CommonJS mismatch. This fixes said compatibility issue so that the issue doesn't repeat for anybody else. Otherwise this is a critical blocker for anyone just cloning the repo and following the README instructions.

Change list

  • Added a helper utility to dynamically import ESM modules (createWebDavClient.ts)
  • Updated logFile.service.ts to use the new helper
  • TSConfig was adjusted (module: es2020) to allow import.meta.url usage safely

Related issue

Closes #751

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Fix ESM compatibility for 'webdav' package in CommonJS context

4 participants