【问题标题】:Uncaught Error: Module name "util" has not been loaded yet for context: _. Use require([])未捕获的错误:尚未为上下文加载模块名称“util”:_。使用要求([])
【发布时间】:2021-09-01 07:04:27
【问题描述】:

我正在使用第三方js文件来格式化json。 js文件格式如下。

'use strict';

var util = require('util'),
    EE = require('events').EventEmitter;


module.exports = JSONTreeView;
util.inherits(JSONTreeView, EE);


function JSONTreeView(name_, value_, parent_, isRoot_){
    var self = this;

    if (typeof isRoot_ === 'undefined' && arguments.length < 4) {
        isRoot_ = true;
    }

    EE.call(self);

    if(arguments.length < 2){
        value_ = name_;
        name_ = undefined;
    } 
 }

这是 node.js 格式。但我的项目是使用 require js 的 ojet。

当我在 html 中加载文件时,出现错误 未捕获的错误:尚未为上下文加载模块名称“util”:_。使用 require([])。

【问题讨论】:

    标签: javascript node.js requirejs


    【解决方案1】:

    NodeJS 使用不同的模块格式——CommonJS。这些格式不兼容。您必须转换它或指示 ReqireJS 如何加载它们。所有信息都可以在RequireJS documentation

    【讨论】:

      猜你喜欢
      • 2023-04-08
      • 1970-01-01
      • 2021-06-04
      • 2016-11-16
      • 1970-01-01
      • 2022-09-26
      • 1970-01-01
      • 1970-01-01
      • 2020-06-03
      相关资源
      最近更新 更多