【发布时间】:2015-11-11 08:40:31
【问题描述】:
我在我的项目中使用jspm。
但是我需要服务器端的 nodejs 文件来执行一些指令。
例如,我需要使用lodash,并在https://github.com/systemjs/systemjs中找到了指南
var System = require('jspm').Loader();
System.import('lodash').then(function (_) { console.log(_); });
但是,我想在全球范围内使用 lodash。 就像
var _ = System.import('lodash');
var myArr = _.map([1, 2, 3], function(n) { return n * 3; });
它会显示
TypeError: _.map 不是函数 在对象。 (/Users/joyfeel/javascript/jspm-test/index.js:49:16) 在 Module._compile (module.js:435:26) 在 normalLoader (/usr/local/lib/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:199:5) 在 Object.require.extensions.(匿名函数) [as .js] (/usr/local/lib/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:216:7) 在 Module.load (module.js:356:32) 在 Function.Module._load (module.js:311:12) 在 Function.Module.runMain (module.js:467:10) 在对象。 (/usr/local/lib/node_modules/babel/lib/_babel-node.js:144:25) 在 Module._compile (module.js:435:26) 在 Object.Module._extensions..js (module.js:442:10)
为什么lodash 只能在.then 范围内使用?
谁能告诉我怎么解决?假设我们要System.import其他模块并使用它?
【问题讨论】: