发布到 npm 的问题
Issue with publishing to npm
所以我正在尝试使用 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
如果有人能帮我解决这个问题,那就太好了。提前致谢!
为了将 React 库推送到 NPM,您可能需要一些样板文件来为您安装和转换许多东西。
=====
我还成功地将几个 React 库推送到 NPM 中:
https://www.npmjs.com/~thinhvo0108
https://www.npmjs.com/package/react-sticky-dynamic-header
https://www.npmjs.com/package/react-ringing-bell
=====
您的 github 存储库的文件夹结构也应该与我的类似:
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/
所以我正在尝试使用 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
如果有人能帮我解决这个问题,那就太好了。提前致谢!
为了将 React 库推送到 NPM,您可能需要一些样板文件来为您安装和转换许多东西。
=====
我还成功地将几个 React 库推送到 NPM 中:
https://www.npmjs.com/~thinhvo0108
https://www.npmjs.com/package/react-sticky-dynamic-header
https://www.npmjs.com/package/react-ringing-bell
=====
您的 github 存储库的文件夹结构也应该与我的类似:
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/