systemjs - 如果文件包含 "use strict","system.import" 失败

systemjs - "system.import" fails if file contains "use strict"

我想在新项目中使用 systemjs 作为模块加载器。一切正常,直到我添加 'use strict';到应该加载的文件的顶部。

script.js

System.import('loadme.js').then(function(m) {
    console.log('loaded');
    console.log(app);
})

loadme.js

'use strict'; //if I remove this line the import works fine
var app={
  version:'0.0.0',
  name:'just a test'
};

我这里有个小伙伴https://plnkr.co/edit/bhSTkcZw9XaKszXuIYZQ

它期望一个模块与数据一起传回,而不是一个全局变量(参见 strict mode globals 上的文档)。

如果您只是想让它正常工作,您可以执行以下操作: https://plnkr.co/edit/pVKqfGkcCagyLixtmziB?p=preview

'use strict';

var app = {
  version: '0.0.0',
  name: 'just a test'
};

module.exports = app;

/*
  You can also do

  module.exports = {
    app: app,
    foo: foo,
    bar: bar
    .
    .
    .
  }

  and then in your script.js have module.app, module.foo

*/