webstorm无法识别“require"关键字 [英] 'require' keyword not being recognized by webstorm

查看:30
本文介绍了webstorm无法识别“require"关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 WebStorm 作为 IDE.

I'm using WebStorm as the IDE.

这是我的文件夹结构和 express.js 安装:

Here's my folder structure and express.js insalled:

但我的示例代码不知道 require 关键字:

But my sample code is not aware of the require keyword:

var express = require('express');
var app = express();

app.listen(1337, function(){
    console.log("ready");
});

更新

Per Darin 的回答这是我的 package.json 文件,它现在位于网站文件夹的根目录中:

Per Darin's answer Here's my package.json file which now sits in the root of the Website folder:

{
  "name": "MyTestSite.com",
  "version": "0.0.1",
  "description": "A Website",
  "main": "test.js",
  "directories": {
    "test": "tests"
  },
  "dependencies": {
    "express": "^4.11.2"
  },
  "devDependencies": {},
  "scripts": {
    "test": "n/a"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/n/a"
  },
  "keywords": [
    "express"
  ],
  "author": "My Name",
  "license": "n/a",
  "bugs": {
    "url": "https://github.com/n/a/issues"
  },
  "homepage": "https://github.com/n/a"
}

这是用 npm init 创建的.我认为我不需要那里的所有废话,所以现在我只需要:

This was created with npm init. I don't think I need all that crap in there so now I just have:

{
  "name": "MyTestSite.com",
  "version": "0.0.1",
  "description": "A Website",
  "main": "test.js",
  "directories": {
    "test": "tests"
  },
  "dependencies": {
    "express": "^4.11.2"
  }
}

我这里肯定有一些格式不正确的东西...WebStorm 仍然无法识别 require 关键字.

I must have something malformed here...WebStorm still doesn't recognize the require keyword.

require 是 npm 的关键字,不是吗?

require is a keyword for npm isn't it?

推荐答案

在 Webstorm 中,您可以在设置 (ctrl-alt-s) 的三个位置更新 Node.js 的设置项目.

In Webstorm, there are three places in your settings (ctrl-alt-s) where you can update settings for Node.js projects.

设置:Javascript 库

首先,在Javascript |库 您可以指定应加载节点库.您的库集可能看起来与此不同,但应该非常接近……或者,如果需要,您可以添加库,以便显示您的风格(节点、io 等).

First, in Javascript | Libraries you can specify that Node libraries should be loaded. Your set of libraries may look different than this, but it should be pretty close...or, if needed, you can add the libraries so that your flavor (node, io, whatever) shows up.

JSHint

其次,如果您启用了 JSHint,您还应该启用 Node.js 环境,以便 JSHint 正确运行.

Second, if you have JSHint enabled, you should also enable the Node.js environment so that JSHint acts appropriately.

Nodejs 和 NPM 设置

您还可以(应该)设置节点可执行文件的路径.Webstorm 还会检测您全局安装的模块,并显示您的版本是否是最新的.

You can (should) also set the path to your node executable. Webstorm will also detect your globally installed modules, too, and show you if your versions are up-to-date.

官方文档

最后,这个参考链接包含更多关于 WebStorm 和 Node 的信息:JetBrains Webstorm -- Nodejs Docs

Finally, this reference link contains much more information about WebStorm and Node: JetBrains Webstorm -- Nodejs Docs

这篇关于webstorm无法识别“require"关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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