SuiteScript 2.0服务器端环境中RequireJS的问题

问题描述 投票:0回答:1

[我们正在尝试让core-js@3在SuiteScript 2.0服务器端执行环境中正常工作,因为它具有所有(非常不错的)ECMAScript 6 polyfill。

该库的捆绑版本似乎工作正常。例如,这在脚本调试器中可以正常运行:

/**
 * @NApiVersion 2.x
 */
require(['/SuiteScripts/core'],
  function() {
    var test = Array.from(new Set([1, 2, 3, 2, 1]));
  }
);

((/ SuiteScripts / core.js是version 3.6.4 bundled version of the library。]

但是,我们更喜欢使用库的标准(非捆绑式)版本,因为这将使我们能够选择性地仅加载所需的功能。我们将库的3.6.4版本上传到了文件柜,然后尝试加载它:

File Cabinet

/**
 * @NApiVersion 2.x
 */
require(['/SuiteScripts/core-js'],
  function() {
    var test = Array.from(new Set([1, 2, 3, 2, 1]));
  }
);

这将导致以下错误:

{"type":"error.SuiteScriptModuleLoaderError","name":"MODULE_DOES_NOT_EXIST","message":"Module does not exist: /SuiteScripts/core-js.js","stack":["<anonymous>(adhoc$-1$debugger.user:4)"]}

[似乎RequireJS在SuiteScript 2.0环境中做的事情很奇怪,因为通常,从require()引用目录会导致RequireJS在目录中寻找index.js吗?如果我们直接引用目录中的index.js文件,那么当index.js文件尝试将require('./es')子目录es时,我们将得到一个不同的错误:

/**
 * @NApiVersion 2.x
 */
require(['/SuiteScripts/core-js/index'],
  function() {
    var test = Array.from(new Set([1, 2, 3, 2, 1]));
  }
);

错误消息:

{"type":"error.SuiteScriptModuleLoaderError","name":"{stack=[Ljava.lang.Object;@73882a5d, toJSON=org.mozilla.javascript.InterpretedFunction@53fe9f7f, name=MODULE_DOES_NOT_EXIST, toString=org.mozilla.javascript.InterpretedFunction@32f5a028, id=, message=Module does not exist: /es.js, TYPE=error.SuiteScriptModuleLoaderError}","message":"","stack":["<anonymous>(adhoc$-1$debugger.user:4)"]}

我们已经尝试了各种修改RequireJS配置的机制,但没有成功,这些机制在NetSuite文档和Web上建议使用,例如@NAmdConfig /Directory/... JSDoc参数和require.config(...)。在我们尝试过的每个执行上下文中,@NAmdConfig似乎都被完全忽略了,并且require.config(...)不能用于改变主要的RequireJS上下文配置。

index.js分辨率在SuiteScript 2.0的RequireJS实现中是否简单地打破了?有什么解决方法吗?

netsuite suitescript2.0
1个回答
0
投票

NetSuite使用require的定制版本,没有关于所说定制确切含义的文档。为了获得最佳结果,您将要使用所需的任何库的缩小的汇总版本。

[如果要选择core-js的功能,则应使用webpackrollup或要以所需方式构建库的任何编译工具,然后将单个结果文件导入SuiteScript模块中。

或者,如果您的目标是ES6 +功能,则可以尝试使用SuiteScript 2.1。

© www.soinside.com 2019 - 2024. All rights reserved.