denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
94.61k stars 5.25k forks source link

node-compat: `@commitlint/cli`dynamic package not installed #17175

Open TillaTheHun0 opened 1 year ago

TillaTheHun0 commented 1 year ago

I was trying to use commitlint, to "lint" commit messages, but am getting this error:

error: Uncaught Error: Empty filepath.
    at pathDirname (deno:ext/node/02_require.js:50:13)
    at new Module (deno:ext/node/02_require.js:255:17)
    at Function.Module._resolveFilename (deno:ext/node/02_require.js:553:30)
    at Function.resolve (deno:ext/node/02_require.js:811:21)
    at projectLocalResolveHelper (file:///home/gitpod/.cache/deno/npm/registry.npmjs.org/ts-node/10.9.1/dist/util.js:117:24)
    at resolveCompiler (file:///home/gitpod/.cache/deno/npm/registry.npmjs.org/ts-node/10.9.1/dist/configuration.js:232:22)
    at resolveAndLoadCompiler (file:///home/gitpod/.cache/deno/npm/registry.npmjs.org/ts-node/10.9.1/dist/configuration.js:225:26)
    at findAndReadConfig (file:///home/gitpod/.cache/deno/npm/registry.npmjs.org/ts-node/10.9.1/dist/configuration.js:48:28)
    at create (file:///home/gitpod/.cache/deno/npm/registry.npmjs.org/ts-node/10.9.1/dist/index.js:146:69)
    at register (file:///home/gitpod/.cache/deno/npm/registry.npmjs.org/ts-node/10.9.1/dist/index.js:127:19)

Steps to Reproduce:

In any git repo (with at least 1 commit), run deno run --allow-read --allow-env --allow-run npm:@commitlint/cli@^17 -x @commitlint/config-conventional --from=HEAD

Expected

commitlint will validate the commit message of HEAD and exit with a 0 status code

Actual

deno crashes due to the uncaught error above.

GJZwiers commented 1 year ago

The Empty filepath issue looks fixed on 1.32.3 (since 8c051dbd1a075ad3c228f78b29b13f0e455972a7) but a different error is thrown, similar to https://github.com/denoland/deno/issues/17176#issuecomment-1364319257

marvinhagemeister commented 5 months ago

I cannot reproduce the described Empty filepath issue anymore. Instead I get an error that the npm package that was passed via the -x flag cannot be found:

error: Uncaught Error: Cannot find module "@commitlint/config-conventional" from "/Users/marvinhagemeister/dev/test/commitlint"

Digging through the code the config is ultimately loaded here:

const dynamicImport = async <T>(id: string): Promise<T> => {
    const imported = await import(
        path.isAbsolute(id) ? pathToFileURL(id).toString() : id
    );
    return ('default' in imported && imported.default) || imported;
};

https://github.com/conventional-changelog/commitlint/blob/736ff624f9496ba1f804df46627aa1996d16a108/%40commitlint/resolve-extends/src/index.ts#L13-L15