所以我正在尝试使用react构建一个开源项目并将其推送到npm。问题是,我的组件,虽然它们在测试环境中运行良好 - 安装到其他组件但是当我将它发布到npm并下载软件包并尝试访问它时,它给了我一个错误。
以下是代码的一小部分示例
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
如果有人可以帮我解决这个问题,那就太好了。提前谢谢!
答案 0 :(得分:2)
为了将反应库推送到NPM,你可能需要一些样板来安装和转换很多东西。
=====
我还成功地将几个反应库推入NPM:
https://www.npmjs.com/~thinhvo0108
https://www.npmjs.com/package/react-sticky-dynamic-header
https://www.npmjs.com/package/react-ringing-bell
=====
您的github存储库&#39;文件夹结构也应该像我的:
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/