Esm: Interoperability with pkg

Created on 13 Apr 2019  路  3Comments  路  Source: standard-things/esm

I'm trying to get pkg working with esm and I've hit an issue which I can't seem to trackdown the source.

TypeError: this._checkModeProperty is not a function
    at Object.Stats.isFile (internal/fs/utils.js:183:15)
    at Object.<anonymous> (/snapshot/express-es6/index.js:4:1)
    at Module._compile (pkg/prelude/bootstrap.js:1254:22)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:711:10)
    at Module.load (internal/modules/cjs/loader.js:610:32)

To reproduce:

git clone https://github.com/OmgImAlexis/pkg
cd pkg/examples/express-es6
npm -g pkg
pkg .
./express-example
bug

Most helpful comment

Any updates?

I also came across this need, and I am doing some experiments to try to get esm work with pkg. Here is what I've found:

  1. pkg is using vm.Script to compile source code into v8 byte code. For that to happen, I will need to get the "transformed" javascript code. Is there any programmtical usage of esm to expose the transformed code?
  2. pkg has some "prelude" code to be executed before any other source. In there, pkg would overwrite fs and module functions (as @OmgImAlexis has mentioned earlier). So my plan is to execute esm first, and then execute the prelude code.

All 3 comments

I'm assuming it's got something todo with how they change require.

https://github.com/zeit/pkg/blob/4bdbd6a95f64479a3e651a155fa0d72f1f38c489/prelude/bootstrap.js#L1145-L1313

Any updates?

I also came across this need, and I am doing some experiments to try to get esm work with pkg. Here is what I've found:

  1. pkg is using vm.Script to compile source code into v8 byte code. For that to happen, I will need to get the "transformed" javascript code. Is there any programmtical usage of esm to expose the transformed code?
  2. pkg has some "prelude" code to be executed before any other source. In there, pkg would overwrite fs and module functions (as @OmgImAlexis has mentioned earlier). So my plan is to execute esm first, and then execute the prelude code.

This is fixed with Node >= 13 but PKG doesn't yet support it. Related:

https://github.com/zeit/pkg/issues/838

Was this page helpful?
0 / 5 - 0 ratings