发布到npm的问题 [英] Issue with publishing to npm

查看:2023
本文介绍了发布到npm的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图使用react构建一个开源项目并将其推送到npm.问题是,我的组件虽然可以在测试环境中很好地工作-可以安装到其他组件上,但是当我将其发布到npm并下载该软件包并尝试访问它时,却给我一个错误.

So I am trying to build an Open Source project using react and pushing it to npm. The issue is, my components, while they work great on a test environment - mounted to other components but when I publish it to npm and download the package and try to access it, it gives me an error.

这里是代码的一小部分

import React, {Component} from 'react';
import {Nav, NavBar, NavLink, NavItem} from 'react-bootstrap';


class GitNav extends Component{
    handleSelect(eventKey){
      window.location = this.props.NavURLs[eventKey];
    }
  render(props){
    const NavTextItems = this.props.NavTexts.map((eachNav, key) =>
      <NavItem eventKey={key} href="#">{eachNav}</NavItem>
      );
    return(
      <Navbar fixedBottom collapseOnSelect>
          <Navbar.Header>
            <Navbar.Toggle />
          </Navbar.Header>
            <Navbar.Collapse>
              <Nav onSelect={this.handleSelect.bind(this)}>
                {NavTextItems}
              </Nav>
            </Navbar.Collapse>
          </Navbar>
    );
  }
}

export default GitNav;

这是错误:

Error in ./~/react-github-nav/index.js
Module parse failed: /Users/theawesomeguy/Desktop/Projects/resume3/resume/node_modules/react-github-nav/index.js Unexpected token (11:6)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (11:6)
 @ ./src/App.js 20:22-49

如果有人可以帮助我解决这个问题,那就太好了.预先感谢!

If anyone can help me out with this, that will be great. Thanks in advance!

推荐答案

为了将React库推入NPM,您可能需要一些样板文件,它将为您安装和转换许多东西.

In order to push react libraries into NPM, you may need some boilerplate which will install and convert many things for you.

=====

我还成功地将几个反应库推入NPM:

I've also pushed several react libraries successfully into NPM:

https://www.npmjs.com/~thinhvo0108

https://www.npmjs.com/package/react-sticky -dynamic-header

https://www.npmjs.com/package/react-ringing-bell

=====

您的github存储库的文件夹结构也应该像我的一样:

Your github repositories' folder structure should also look like mine:

https://github.com/thinhvo0108/react-sticky-dynamic-header

https://github.com/thinhvo0108/react-ringing-bell

=====

下面的有用教程:

(样板源) https://github.com/juliancwirko/react-npm-boilerplate

(作者的文章) http://julian.io/creating- react-npm-packages-with-es2015/

这篇关于发布到npm的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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