【问题标题】:ran npm install on github but cant import the javascript files在 github 上运行 npm install 但无法导入 javascript 文件
【发布时间】:2017-01-06 22:56:41
【问题描述】:

我在 github 上名为“react-slingshot-Boilerplate”的项目上成功运行了 npm install。在 node_modules 文件夹中,我可以在运行 npm install 后看到项目“react-slingshot-Boilerplate”。我还可以在该 node_modules 包中找到我想要导入的组件。

这是我尝试将 npm 安装的组件导入 INTO 的组件:

import {LoginPage} from 'react-slingshot-Boilerplate';

class login2 extends React.Component {
    constructor(props) {
        super(props);

    }

    render() {
        return (
            <div className="login-container">
                <LoginPage></LoginPage>
            </div>
        );
    }
}

这是我要导入的组件:

class LoginPage extends React.Component {
             constructor(props) {
                 super(props);
             }

    render() {
            return (
                <div >
                    <h1 >hello world</h1>
               </div>
     );
  }

 export default connect(mapStateToProps, mapDispatchToProps)(LoginPage);

【问题讨论】:

  • 找不到任何具有此名称 react-slingshot-Boilerplate 的 Github 项目/npm 模块。能给个链接吗?

标签: node.js reactjs npm


【解决方案1】:

导入名称有问题。您为类和导入包保持相同的名称,请参阅:

//LoginPage作为类名和导入名重复。

import {LoginPage} from 'react-slingshot-Boilerplate';

class LoginPage extends React.Component {

注意:npm install 将安装所有注册到 npm 的库,直接将文件保存到 node_module 文件夹并运行npm install 将不起作用。

【讨论】:

  • 那么你正在导出错误的组件 export default connect(mapStateToProps, mapDispatchToProps)(LoginPage);代替 LoginPage 它应该是 login2
  • 非常抱歉。我把我的问题搞砸了。我试图在上面修复它。如果你和我一起失去病人,我完全理解。 :(
  • 没关系,我明白 :)
  • 在第二个组件中您要导入什么?
  • 你能给我一个 react-native-slingshot 的链接或者你已经创建了自己的 npm 库吗?
猜你喜欢
  • 1970-01-01
  • 2022-07-22
  • 2016-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-21
  • 2018-04-12
  • 2015-08-25
相关资源
最近更新 更多