ecomfe / esl

enterprise standard loader
BSD 3-Clause "New" or "Revised" License
845 stars 228 forks source link

使用data-main,并在config中设置waitSeconds出错 #83

Closed zhengmz closed 4 years ago

zhengmz commented 4 years ago

一、使用过程

  1. 使用最新的版本: esl@2.2.2-beta.1

  2. index.html文件内容:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Test</title>
    </head>
    <body>
    <script src="node_modules/esljs/dist/esl.js" data-main="index"></script>
    </body>
</html
  1. index.js文件内容
require.config({
    baseUrl: './src',
    paths: {
        san: '../node_modules/san/dist/san.dev',
        'san-router': '../node_modules/san-router/dist/san-router.source'
    },
    waitSeconds: 5
});
require(['main'], function (main) {  //此处为报错点
    main.start();
});
  1. main.js文件内容
define(function(require) {
    return {
        start: function () {
            console.log('application start...');
        }
    };
})

二、出错信息

[MODULE_TIMEOUT]Hang: none; Miss: index

但实际已经加载进来,也能正常打印日志。

三、两种临时补救

  1. 去掉waitSeconds配置
  2. 将index.js直接写在index.html中

四、在requirejs中表现是正常的

zhengmz commented 4 years ago

我猜因为index.js不是一个标准模块,所以出现错误,不知道是不是? @errorrik

为此,我尝试在index.js增加了一个空白的模块定义:

define(function(require) {
    'use strict';
    return {};
})

就不再提示错误。

zhengmz commented 4 years ago

使用define来定义data-main模块,就可以了。