Pkg: Any future support for ES6 Node application

Created on 5 Jun 2018  路  12Comments  路  Source: vercel/pkg

Any future updates for supporting ES6 node application. My application is developed in ES6 compatible code like import which is not supported by PKG.

Most helpful comment

Would love to see support for esm especially as a lot of my dependencies are using it.

All 12 comments

pkg is just using Node and there is information here about using import in Node - https://nodejs.org/api/esm.html

To turn that on in pkg you'll need to see here - https://github.com/zeit/pkg#options

You'd do something like this: pkg app.js --options experimental-modules

You can also use babel to transpile your code and package that instead.

@theogravity did you try to use pkg on a transpiled babel project?

My node transpiled.js worked fine, after building...

But then I got the same error (outup as warning):
https://github.com/zeit/pkg/issues/211

> Warning Failed to make bytecode node8-x64 for file /snapshot/shadertoy/src/main.js
> Warning Failed to make bytecode node8-x64 for file /snapshot/shadertoy/src/ui.js
> Warning Failed to make bytecode node8-x64 for file /snapshot/shadertoy/src/Effect.js

I was just wondering if anyone is able to pkg for linux, windows and mac.
I'm trying to make it work on Arch Linux

@shahajipatil
Ok now this example is working for me:
https://github.com/zoutepopcorn/bapkg

Would love to see support for esm especially as a lot of my dependencies are using it.

I got this error when I use import.meta:

Error! This experimental syntax requires enabling the parser plugin: 'importMeta'

How do I enable a plugin? Parser plugin isn't mentioned in README.

Note that I'm using Node.js 10, which supports import.meta.url. In addition, Babel is not yet ready for import.meta.url, so I cannot simply transpile and make it work.

@sheepsteak's suggestion works as long as there are no imports but something as simple as the following fails:

import os from "os"
console.log(os.hostname())

Saving this to a file called TestESMPKG.js and running pkg .\TestESMPKG.js --options experimental-modules --targets latest-win-x64 --debug results in the following errors:

SyntaxError: Unexpected identifier
    at new Script (vm.js:84:7)
    at Socket.<anonymous> ([eval]:18:19)
    at Socket.emit (events.js:196:13)
    at addChunk (_stream_readable.js:290:12)
    at readableAddChunk (_stream_readable.js:271:11)
    at Socket.Readable.push (_stream_readable.js:226:10)
    at Pipe.onStreamRead (internal/stream_base_commons.js:166:17)
(node:19736) ExperimentalWarning: The ESM module loader is experimental.
C:\snapshot\TestESMPKG\TestESMPKG.js:1
(function (exports, require, module, __filename, __dirname) { import os from "os"
                                                                     ^^

SyntaxError: Unexpected identifier
    at new Script (vm.js:84:7)
    at Socket.<anonymous> ([eval]:18:19)
    at Socket.emit (events.js:196:13)
    at addChunk (_stream_readable.js:290:12)
    at readableAddChunk (_stream_readable.js:271:11)
    at Socket.Readable.push (_stream_readable.js:226:10)
    at Pipe.onStreamRead (internal/stream_base_commons.js:166:17)
> Warning Failed to make bytecode latest-x64 for file C:\snapshot\TestESMPKG\TestESMPKG.js

@ChrisMagnuson wouldn't you need to use .mjs since you're using the experimental-modules flag?

Did some of you succeeded to use pkg without transpiling? @OmgImAlexis @ChrisMagnuson

I gave up and webpacked my node backend -- got it packaged. Still struggling with __dirname pathing to runtime assets, as __dirname is no more with type="module".

@gmcdev __dirname can be obtained from module.import in ESM modules, but unfortunately, it looks like that doesn't work either:

Error! import.meta may appear only with 'sourceType: "module"' (54:22)

It is the same with --options require=ems and --options experimental-modules. I notice @FranklinYu has posted about the same problem some time ago already so I don't think this will get anytime soon, unfortunately.

Still fail

pkg index.mjs --targets node14-linux-x64
Was this page helpful?
0 / 5 - 0 ratings

Related issues

hellower picture hellower  路  3Comments

peterjwest picture peterjwest  路  3Comments

erikd picture erikd  路  3Comments

Ks89 picture Ks89  路  4Comments

bergheim picture bergheim  路  3Comments