standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.26k stars 146 forks source link

Interoperability with pkg #780

Open OmgImAlexis opened 5 years ago

OmgImAlexis commented 5 years ago

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
OmgImAlexis commented 5 years ago

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

Tundon commented 5 years ago

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.
autr commented 4 years ago

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

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