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

Async/await is not working with this pattern #68

Open
rf00 opened this issue Oct 21, 2016 · 3 comments
Open

Async/await is not working with this pattern #68

rf00 opened this issue Oct 21, 2016 · 3 comments

Comments

@rf00
Copy link

rf00 commented Oct 21, 2016

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'
  }
}
@OrKoN
Copy link

OrKoN commented Oct 21, 2016

@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.

@rf00
Copy link
Author

rf00 commented Oct 21, 2016

@OrKoN It works!

@aluanhaddad
Copy link

@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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants