Pkg error : "import.meta may appear only with 'sourceType: "module"'

Viewed 612

i'm evaluating pkg (https://www.npmjs.com/package/pkg) but when I launch it I have the error :

import.meta may appear only with 'sourceType: "module"'

My Nodejs application uses the Es6 "import" syntax (ex. import {gxAppl, wxcSysBase, wxeClassCap} from '../../../wGx/src/commun/sys/wxmSysBase.mjs')

Any suggestions ?

Thanks in advance

1 Answers

The short answer seems to be that pkg currently only supports node v14.x, which doesn't handle import.meta. See https://vercel.com/docs/runtimes for supported node versions.

If your import.meta was a replacement for __dirname, you might be able to make use of other parts of the snapshot filesystem. For example something like

function getAppDir () {
    if(process.pkg && process.pkg.entrypoint) {
        return path.dirname(process.pkg.entrypoint); }
    return process.cwd();
}

See https://github.com/vercel/pkg for details on the snapshot filesystem.

Related