2

Why do I have to use the .js extension to import es6 module with systemjs? For instance:

import { multiplier } from "adder.js"; // ok
import { double, square } from 'modules'; // error

var timesTwo = multiplier(2);

console.log(timesTwo(4));

The error message:

GET http://local-host/projects/es6/src/modules 404 (Not Found)Z @ system.js:4(anonymous function) @ system.js:4(anonymous function) @ system.js:4(anonymous function) @ system.js:5(anonymous function) @ system.js:5(anonymous function) @ system.js:5(anonymous function) @ system.js:5(anonymous function) @ system.js:5(anonymous function) @ system.js:5(anonymous function) @ system.js:4 system.js:4 Uncaught (in promise) Error: Error: XHR error (404 Not Found) loading http://local-host/projects/es6/src/modules(…)

This is my HTML with system.js:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ES2015 Module Example</title>
</head>
<body>
    <script src="lib/system.js"></script>
    <script>
        System.config({
            "baseURL": "src",
            // 'plugin-babel' or 'traceur' or 'typescript'
            transpiler: 'plugin-babel',
            // or traceurOptions or typescriptOptions
            babelOptions: {

            },
            map: {
                'traceur': './lib/traceur.min.js',
                'plugin-babel': './lib/plugin-babel/plugin-babel.js',
                'systemjs-babel-build': './lib/plugin-babel/systemjs-babel-browser.js'
            }
          }
        });
        System.import("app.js");
    </script>
</body>
</html>

Any ideas what have I missed?

4

1 回答 1

2

因为系统 js 不附加.js到模块名称。一些模块加载器/捆绑器(Node、webpack 等)正在这样做,但没有标准规定必须这样

对此有一个配置选项,但将被弃用。

于 2016-05-25T15:19:07.680 回答