在requirejs中只声明一次时,模块共享相同的url

Modules share the same url when only declared once in requirejs

本文关键字:模块 共享 url 一次 requirejs 声明      更新时间:2023-09-26

我正在使用requirejs编写一个应用程序。我编写的一些模块只需加载多个组件即可轻松访问。当我通过requirejs优化器运行应用程序时,这些模块会导致以下错误:

The following modules share the same URL. This could be a misconfiguration if that URL only has one anonymous module in it:
F:/nemesis/nemesis/src/nemesis.js: nemesis, nemesis
F:/nemesis/nemesis/src/_nemesis.js: _nemesis, _nemesis
F:/nemesis/nemesis/src/rendering/rendering.js: rendering/rendering, rendering/rendering] }

以下是它如何定义每个模块。

nemesis.js

define(["require", "exports", "_nemesis", 'rendering/rendering'], function(require, exports, _nemesis, Rendering) {
    /* Definition code */
});

_nemesis.js

define(["require", "exports", "json!config.json"], function(require, exports, config) {
    /* Definition code */
});

rendering/rendering.js

define(["require", "exports", "_nemesis", "./shaders", "./primitive", "util/logging/consoleLogger"], function(require, exports, nemesis, Shaders, Render, Logger) {
    /* Definition code */
});

最后,这就是我要求配置的方式:

baseUrl: "src/",
name: "<%= pkg.name %>",
paths: {
    text: "../node_modules/text/text",
    json: "../lib/requirejs-plugins/json",
    "config.json": 'empty'
},
out: 'build/<%= pkg.name %>.js',
optimize: 'none'

是否配置或声明模块错误,或者我在配置中遗漏了什么?

此外,我们从typescript生成的模块声明。typescript编译器的不同参数能解决这个问题吗?

我发现问题出在路径中的"config.json"。将其更改为

config: 'empty:'

使所有内容都按预期编译。然而,我不确定为什么这会导致我得到的错误,或者为什么

"config.json" : 'empty:'

不起作用,所以如果有人能解释一下,我将不胜感激。