简体   繁体   English

配置从node_modules读取的requirejs

[英]configuring requirejs reading from node_modules

I'm trying to setup a nodejs project to use requirejs. 我正在尝试设置nodejs项目以使用requirejs。 I call my program with node r.js ./config/main.js and my main.js looks like the following: 我用node r.js ./config/main.js调用我的程序,我的main.js如下所示:

var cs = require("coffee-script");
var requirejs = require("requirejs");

requirejs.config({
  nodeRequire: require,
  baseUrl: ".",
  paths: {
    cs: "cs",
    CoffeeScript: "CoffeeScript",
    csBuild: "csBuild",

    express: "express",
    nohm: "nohm",
    redback: "redback",
    _: "underscore",
    "connect-redis": "connect-redis",
    freebase: "freebase"
   }
});

console.log("hetet");
requirejs(["cs!./config/app"], function(app){
  console.log("closing")
});

and inside app.coffee: 在app.coffee里面:

define((require) ->

  express = require("express")

  RedisStore = require("connect-redis")(express)
  app = express.createServer()

  config = require('cs!./config')

  require('cs!./setup')(app, express, RedisStore)
  require('cs!./routes')(app)
  require('cs!../src/server')

  app.listen(config.server.port)
)

I seem to fail in main.js with the error: 我似乎在main.js中失败并出现错误:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: Calling node's require("config") failed with error: Error: Calling node's require("config") failed with error: Error: Cannot find module 'config'

and What I have noticed is when I comment out the line var requirejs = require("requirejs"); 我注意到的是当我注释掉行var requirejs = require("requirejs"); (in main.js), I get further and fail at the line RedisStore = require("connect-redis")(express) (in app.coffee) with the error: (在main.js中),我进一步失败了RedisStore = require("connect-redis")(express) (在app.coffee中)并出现错误:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
TypeError: undefined is not a function
    at ./config/app.coffee:10:41

I have been having a lot of trouble configuring requirejs in node any help would be appreciated. 我在节点中配置requirejs时遇到了很多麻烦,任何帮助都会受到赞赏。

thanks 谢谢

It is best to not configure requirejs to look in node_modules, since modules in that area are modules formatted for node. 最好不要将requirejs配置为查看node_modules,因为该区域中的模块是为节点格式化的模块。 There is a little bit more info in the requirejs node page . requirejs节点页面中有更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM