【发布时间】:2014-07-26 13:45:04
【问题描述】:
如何在 RequireJS 中为模块分配变量?
换句话说,RequireJS 相当于什么:
var fs = require('fs');
var child_process = require('child_process');
我想将这些模块保存在它们各自的变量中,以便稍后调用它们的函数并处理它们。
编辑:
我尝试使用 Marco 的建议,这是我得到的错误:
Failed to load resource: the server responded with a status of 404 (Not Found) localhost/fs.js
Uncaught Error: Script error for: fs requirejs.org/docs/errors.html#scripterror
然后我将 fs.js 文件直接放在项目目录中,现在错误提示:
Uncaught Error: Module name "fs" has not been loaded yet for context: _. Use require([]) requirejs.org/docs/errors.html#notloaded
Uncaught TypeError: Cannot read property 'writeFile' of undefined
请为此提出一些解决方法。
【问题讨论】:
标签: javascript node.js web requirejs commonjs