node.js 未找到模块:错误:无法解析“react-bootstrap-validation”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39404267/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 20:33:15  来源:igfitidea点击:

Module not found: Error: Can't resolve 'react-bootstrap-validation'

node.jsreactjsnpmreact-bootstrap

提问by Giwoo Gustavo Lee

Issue

问题

I keep getting the following error in webpack

我在 webpack 中不断收到以下错误

Error: Cannot find module 'react-bootstrap-validtion'
    at Function.Module._resolveFilename (module.js:339:15)
    at Function.Module._load (module.js:290:25)
    at Module.require (module.js:367:17)
    at require (internal/module.js:20:19)

Have I referenced or installed the module incorrectly?

我是否错误地引用或安装了模块?

This is how I've done it following the example in the official website. (https://www.npmjs.com/package/react-bootstrap-validation)

这是我按照官方网站上的示例完成的。( https://www.npmjs.com/package/react-bootstrap-validation)



Environment

环境

This are the node environment I'm working with

这是我正在使用的节点环境

npm -v
3.10.7

nvm version
v5.11.1

node -v
v5.11.1


This is how I've installed the module

这就是我安装模块的方式

npm install --save react-bootstrap-validation

npm install --save react-bootstrap-validation



React Component

反应组件

This is how I've implemented my React component

这就是我实现我的 React 组件的方式

import React, {Component} from 'react'
import { ButtonInput } from 'react-bootstrap'
import { Form } from 'react-bootstrap-validation'

export default class LoginForm extends Component {

  constructor(props) {
    super(props)
    this.state = {
      showModal: false,
      email: '',
      password: ''
    }
  }

  _handleValidSubmit(values) {}
  _handleInvalidSubmit(errors, values) {}

  render() {
    return (
      <div>
        <div className="account">
          <div className="container">
            <div className="page-title">Login</div>
            <div className="page-desc">Email used at sign up</div>
            <Form
              onValidSubmit={this._handleValidSubmit.bind(this)}
              onInvalidSubmit={this._handleInvalidSubmit.bind(this)}>
              <ValidatedInput
                type="text"
                label="Email"
                name="email"
                validate="required,isEmail"
                errorHelp={{
                  required: "Please enter your e-mail",
                  isEmail: "Email is invalid"
                }}
              />

              <ValidatedInput
                type="password"
                label="Password"
                name="password"
                validate="required,isLength:6:60"
                errorHelp={{
                  required: "Please specify a password",
                  isEmail: "Password must be at least 6 characters"
                }}
              />

              <ButtonInput
                type="submit"
                bsSize="large"
                bsStyle="primary"
                value="LOGIN"
              />
            </Form>
          </div>
        </div>
      </div>
    )
  }
}

回答by Parveen yadav

Module not found error occur when you are using some module and that module is not installed or node is unable to locate that module due to wrong path.

当您使用某个模块而该模块未安装或节点由于路径错误而无法定位该模块时,会发生找不到模块错误。

One module you are trying to install have either dependency on other modules as well

您尝试安装的一个模块也依赖于其他模块

so sometime not all the modules are installed correctly due to some permission security issues.

因此有时由于某些权限安全问题,并非所有模块都正确安装。

So please try with giving all permission or run as Root and add sudo if yoy are using ubuntu machine.

因此,如果您使用的是 ubuntu 机器,请尝试授予所有权限或以 Root 身份运行并添加 sudo。

So you can install that module via directly running the following command:-

因此,您可以通过直接运行以下命令来安装该模块:-

npm install react-bootstrap-validtion --save

or if you are using linux/ubuntu than run following command:-

或者,如果您使用的是 linux/ubuntu,请运行以下命令:-

sudo npm install react-bootstrap-validtion --save

Or first please check in the console when installing the module that

或者首先请在安装模块时在控制台中检查

is there any dependency error showing in the console

控制台中是否显示任何依赖错误

if so than please also attach that console, on that case you need to install dependent module also as separately via npm install.

如果是这样,请同时附加该控制台,在这种情况下,您还需要通过 npm install 单独安装依赖模块。

Hope this will help!

希望这会有所帮助!

Thanks

谢谢

回答by pranavi reddy

You can try to use this:

你可以尝试使用这个:

npm i --save react-bootstrap