Skip to content
This repository was archived by the owner on Oct 9, 2020. It is now read-only.
This repository was archived by the owner on Oct 9, 2020. It is now read-only.

Async/await is not working with this pattern #68

Open

Description

@rf00

This one works:

//boot.js
var main = require('./main.js')

main.boot()

//main.js

export async function boot() {
  await new Promise(function(resolve, reject) {
    console.log('hello world');
    setTimeout(function() {
      resolve();
    }, 1000);
  })
  console.log('hello world after 1s!');
}

This one works with webpack but systemjs:

//boot.js
var main = require('./main.js')

//main.js

(async function boot() {
  await new Promise(function(resolve, reject) {
    console.log('hello world');
    setTimeout(function() {
      resolve();
    }, 1000);
  })
  console.log('hello world after 1s!');
})()

Not sure is it an issue

Edit:
Works after adding this:
export var p = 5;
More precisely, in configuration:

meta: {
  './js/main.js': {
    format: 'esm'
  }
}

Activity

  1. OrKoN commented on Oct 21, 2016

    @OrKoN

    @rf00 AFAIK, systemjs classifies a module as an ES6 module only if there are import/export statements. Otherwise it assumes it is ES5 and does not apply the transpiler.

  2. rf00 commented on Oct 21, 2016

    @rf00
    Author

    @OrKoN It works!

  3. aluanhaddad commented on Aug 15, 2017

    @aluanhaddad

    @rf00 AFAIK, systemjs classifies a module as an ES6 module only if there are import/export statements. Otherwise it assumes it is ES5 and does not apply the transpiler.

    Sort of. Basically, if there is no out-of-band1 metadata specifying the format of a package, files are parsed and a format is inferred based on a number of factors including the presence of import/export statements.

    It is often desirable to specify the source module format declaratively as this may improve performance and does not depend on heuristics2

    1 Out of band in this context would be package configuration such as

    SystemJS.config({
      transpiler: "plugin-babel",
      packages: {
        "app" : {
          // The format of modules within this package will not be inferred by parsing
          // and rather will be assumed to match the specified value
          "format": "esm",
          "meta": {
            "*.js" : {
              "loader": "plugin-babel"
            }
          }
        },
        // the following are just examples for expository purposes
        "jquery": {
          "format": "amd"
        },
        "moment": {
          "format": "cjs"
        },
        "rxjs": {
          "format": "esm",
          // I am a masochist who wants to build RxJS from source
          "map": {
            ".": "./src"
          },
          "defaultExtension": "ts",
          "meta": {
            "*.ts": {
              "loader": "plugin-typescript"
            }
          }
        }
      }
    });

    It may also come in the form of overrides in the jspm registry

    {
      "format": "amd"
    }

    or overrides explicitly provided when installing with jspm on a case by case basis

    $ jspm install jquery --override "{format : 'cjs'}"

    2 See the SystemJS documentation for module-format-detection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions