简体   繁体   中英

Brunch require with node.js modules

I have Brunch set up for ease of compiling JS together, but want to also be able to use a node.js module with require. After trying for a while, I'm stumped. I want to be able to do something like this:

var myJSfile1 = require('foo');
var myJSfile2 = require('bar');
var nodeJSdependency = require('node-fubar');

where app/ contains foo.js and bar.js , and in package.js I have a dependency for node-fubar . What happens, of course, is that when I run brunch watch --server it say it's compiled fine, but whe I open it in the browser, I get the console error of

Error: Cannot find module "node-fubar" from "app"

If I try the following:

var nodeJSdependency = require('../node_modules/node-fubar');

the error changes to:

Error: Cannot find module "node_modules/node-fubar" from "app"

Am I doing something wrong, or is what I'm trying to do not possible? If it's not, how would you suggest going about it? Having the browser and the node dependency are both essential but Brunch may not be (I'm just fond of it).

Thanks in advance!

早午餐不支持Nodejs模块。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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