milesj/packemon

`const __dirname` throw "Property id of VariableDeclarator expected node to be of a type ["LVal"] but instead got "CallExpression""

azu opened this issue · 2 comments

azu commented

packemon throw an error when transpile following code.

Property id of VariableDeclarator expected node to be of a type ["LVal"] but instead got "CallExpression"

const __dirname = 1;

This this a parts of following snippet.

import * as path from "path";
import * as url from "url";

const __filename__ = url.fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename__);
console.log(__dirname);

I know that babel-plugin-cjs-esm-interop transpile __dirname.
But, This error is unexpected.

Expected

No Error

Actual

Error:

Property id of VariableDeclarator expected node to be of a type ["LVal"] but instead got "CallExpression""

Workaround

Avoid to define __dirname variable.

import * as path from "path";
import * as url from "url";

const x = url.fileURLToPath(import.meta.url);
const y = path.dirname(x);
console.log(y);

Reproduce Repository

https://github.com/azu/packemon-mjs-__dirname-error

Thanks, will be resolved by 05722cc

Released!