相关疑难解决方法(0)

节点上的客户端:未捕获的ReferenceError:未定义require

所以,我正在用node/express + jade combo编写一个应用程序.

我有client.js,在客户端加载.在该文件中,我有从其他JavaScript文件调用函数的代码.我的尝试是使用

var m = require('./messages');
Run Code Online (Sandbox Code Playgroud)

为了加载messages.js(就像我在服务器端一样)的内容,然后加载该文件的调用函数.但是,require没有在客户端定义,它会抛出窗体的错误Uncaught ReferenceError: require is not defined.

这些其他JS文件也在客户端的运行时加载,因为我将链接放在网页的标题上.因此,客户端知道从这些其他文件导出的所有函数.

如何从打开服务器套接字messages.js的主client.js文件中的其他JS文件(例如)中调用这些函数?

javascript sockets node.js express pug

277
推荐指数
5
解决办法
55万
查看次数

如何在浏览器中要求CommonJS模块?

在浏览器中加载CommonJS模块作为客户端javascript的最佳方法是什么?

CommonJS模块将其功能放在module.exports命名空间中,通常包含require(pathToModule)在服务器端脚本中.在客户端加载它们不能以相同的方式工作(需要更换,需要考虑异步等)

我找到了模块加载器和其他解决方案:Browserify,RequireJS,yabble等,或者简单地改变模块的方法.您认为最好的方式和原因是什么?

javascript commonjs node.js

59
推荐指数
3
解决办法
4万
查看次数

从输出文件中删除Webpack引导程序

好吧,我知道Webpack允许我们导入包,require这是Webpack的基础设施.

但是,当你不在require条目文件中使用时,这不是没用的吗?

我有这个test.js条目:

console.log('Test');
Run Code Online (Sandbox Code Playgroud)

和输出

/******/ (function(modules) { // webpackBootstrap
/******/    // The module cache
/******/    var installedModules = {};
/******/
/******/    // The require function
/******/    function __webpack_require__(moduleId) {
/******/
/******/        // Check if module is in cache
/******/        if(installedModules[moduleId]) {
/******/            return installedModules[moduleId].exports;
/******/        }
/******/        // Create a new module (and put it into the cache)
/******/        var module = installedModules[moduleId] = {
/******/            i: moduleId,
/******/            l: false,
/******/            exports: …
Run Code Online (Sandbox Code Playgroud)

javascript node.js webpack

12
推荐指数
1
解决办法
3549
查看次数

我什么时候需要三斜杠参考?

当Anders Hejlsberg在下面的视频中在35:00左右谈论外部模块时......

Anders Hejlsberg:介绍TypeScript

...为什么文件server.ts需要对node.d.ts的三次斜杠引用,其中hello.ts不需要类似的引用server.ts

特别是hello.ts他提到intellisense存在加上他可以使用从中导出的项目server.ts.那么三重斜杠引用还能增加什么呢?

module typescript

11
推荐指数
1
解决办法
6756
查看次数

我可以在没有requireJS的情况下使用打字稿吗?

我在不同的文件中有两个类:

export class ActionsCollection{
    constructor(greeting :string){
        this.greet(greeting);
    }

    public greet(greeting :string) {
        return "<h1>"+greeting+"</h1>";
    }
} 
Run Code Online (Sandbox Code Playgroud)

import {ActionsCollection} from "./actionsCollection";

class Greeter extends ActionsCollection{
    constructor(public greeting: string) {
        super(greeting); 
    }
}

alert(new Greeter("Hello, world!"));
Run Code Online (Sandbox Code Playgroud)

Greeter在这样的文件中生成,其中存在require行("./ actionsCollection")。但是我想确保所有文件(* .ts)都只在一个文件main.js中生成,不需要require。我可以那样做吗?如果是这样,怎么办?

ps同时,对于装配,您可以使用标准的WebStorm工具和Gulp。而且,除了gulp的模块之外。

javascript typescript

5
推荐指数
1
解决办法
2182
查看次数

Browserify有替代品吗?

我想从Node.js生成客户端JavaScript.我找到了Browserify,但除了Browserify还有其他选择吗?

node.js browserify

0
推荐指数
1
解决办法
2640
查看次数