首页 文章

ES6 SystemJs - 为什么我必须使用.js扩展名来导入es6模块?

提问于
浏览
2

为什么我必须使用.js扩展名来导入带有systemjs的es6模块?例如:

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

var timesTwo = multiplier(2);

console.log(timesTwo(4));

错误消息:

GET http:// local-host / projects / es6 / src / modules 404(Not Found)Z @ system.js:4(匿名函数)@ system.js:4(匿名函数)@ system.js:4(匿名函数)@ system.js:5(匿名函数)@ system.js:5(匿名函数)@ system.js:5(匿名函数)@ system.js:5(匿名函数)@ system.js:5(匿名函数)@ system.js:5(匿名函数)@ system.js:4 system.js:4未捕获(在promise中)错误:错误:XHR错误(404 Not Found)loading http:// local-host / projects / ES6 / SRC /模块(...)

这是我的system.js的HTML:

<!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>

我错过了什么想法?

1 回答

  • 2

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

    这有一个configuration option,但它将被弃用 .

相关问题