Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

es6 modules #926

Closed
naliferov opened this issue Jun 3, 2020 · 10 comments
Closed

es6 modules #926

naliferov opened this issue Jun 3, 2020 · 10 comments

Comments

@naliferov
Copy link

naliferov commented Jun 3, 2020

Hi! What about to pkg of an app that use es6 modules? Is pkg correctly works with such apps?

@marcj
Copy link

marcj commented Jun 11, 2020

Yes

@luxzeitlos
Copy link

It seems not to work for me:

SyntaxError: Unexpected token export
    at new Script (vm.js:84:7)
    at Socket.<anonymous> ([eval]:18:19)
    at Socket.emit (events.js:198:13)
    at addChunk (_stream_readable.js:287:12)
    at readableAddChunk (_stream_readable.js:268:11)
    at Socket.Readable.push (_stream_readable.js:223:10)
    at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
C:\snapshot\app\dist\src\tools\deps-resolver.js:772
export function resolveDeps(detBundles) {
^^^^^^

@pedrohenriquebr
Copy link

Maybe using Babel will works

@luxzeitlos
Copy link

sure, I could transform to AMD or common.js. But thats not the point here. Native ESM does not work.

@Daniel-Olivier
Copy link

Which version of Node JS are you targeting when building your project?

@alexander-girsh
Copy link

@Daniel-Olivier Hi, I had some issue with {type: module} and .mjs/.js files. Node version was 14.4, pkg target was node14-alpine-x64

@Daniel-Olivier
Copy link

Hi @noguilty4you

Are you experiencing the exact same issue and receiving SyntaxError: Unexpected token export errors?

@alexander-girsh
Copy link

@Daniel-Olivier, yes. Yesterday I refactored the whole project to using commonjs modules and so I have no problems =(

@MichaelKorn
Copy link

I took a look at the situation, especially since several open issues are related to es6 modules.
es6 modules are not supported!

  1. The caching cannot work like this:

    pkg/lib/fabricator.js

    Lines 20 to 25 in 52b4933

    var code = module.wrap(body);
    var s = new vm.Script(code, {
    filename: snap,
    produceCachedData: true,
    sourceless: true
    });

    1.1. vm.Script is just for CommonJS modules. For ECMAScript modules vm.Modules and vm.SourceTextModule have be be used.
    1.2. node must be run with --experimental-vm-modules
  2. ECMAScript modules can not be started within the output file (eg. .exe) , because only CommonJS is considered in https://github.com/vercel/pkg/blob/master/prelude/bootstrap.js
    2.1 In particular, _load() is a legacy way to run CommonJS modules:

    pkg/prelude/bootstrap.js

    Lines 1378 to 1381 in 52b4933

    Module.runMain = function () {
    Module._load(ENTRYPOINT, null, true);
    process._tickCallback();
    };

@hipstersmoothie
Copy link
Contributor

closing duplicate of #782

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants