ReferenceError:需求未定义(Webstorm) [英] ReferenceError: Require is not defined (Webstorm)

查看:184
本文介绍了ReferenceError:需求未定义(Webstorm)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图做一些难以置信的基本工作,但是遇到了麻烦.

Trying to do something incredibly basic, but running into a snag.

var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/jetbrains');

var Product = mongoose.model('Product', {name: String});

var product = new Product({name: "WebStorm"});

product.save(function(err) {
    if(err){
        console.log('failed');
    }else{
        console.log('saved');
    }
});

在[文件路径]中未定义持续获取ReferenceError:require的情况.

Continually getting ReferenceError: require is not defined at [file path].

我正在Webstorm 10中进行此操作.尝试遵循有关Webstorm中的MEAN开发的本教程. https://www.youtube.com/watch?v=JnMvok0Yks8

I'm doing this in Webstorm 10. Trying to folow this tutorial on MEAN development in Webstorm. https://www.youtube.com/watch?v=JnMvok0Yks8

想法?

推荐答案

您可能正在尝试在浏览器中运行以上代码.它应该在节点服务器上运行.节点会自动定义require函数,因此您永远不会遇到这个问题.

You are probably trying to run the above code in the Browser. It's supposed to run on the Node server. Node automatically defines the require function so you would never have this problem.

查看此问题以获取入门指南" "材料.

Check out this question for good "getting started" material.

编辑

那真的很奇怪.如果WebStorm在终端上运行,则肯定在运行Node.js.您能否在第一行上放置一个断点,调试文件并检查require函数?

That's really strange. WebStorm is definitely running Node.js if it's running on the Terminal. Can you please put a break point on the first line, debug the file and inspect the require function?

这篇关于ReferenceError:需求未定义(Webstorm)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆