【问题标题】:Heroku cannot find any moduleHeroku 找不到任何模块
【发布时间】:2017-07-10 05:59:43
【问题描述】:

我正在尝试使用流星和 Heroku 开发一个网络应用程序。当我在本地运行我的代码时,一切都很好,但是一旦我在 Heroku 上部署它,我就会得到:

找不到模块'./navbar/NavBar.js'

或者如果我在我的代码中去掉 NavBar:

找不到模块'./component/App'

我的项目文件夹如下所示:

project
  client
    main.css
    main.html
    main.js
      component
        App.js
        Games.js
        Home.js
        Workbench.js
        navbar
          NavBar.js

  Server
    main.js

这是我的代码:

main.js

import React from 'react';
import { Meteor } from 'meteor/meteor';
import { render } from 'react-dom';

import App from './component/App';

Meteor.startup(() => {
  render(<App />, document.getElementById('root'));

});

App.js

import React from 'react';
import {Container} from 'reactstrap';
import {BrowserRouter as Router, Route} from 'react-router-dom';

import Workbench from './Workbench'
import NavBar from './navbar/NavBar.js'

export default class App extends React.Component {
  render(){
    return(
      <Router>
        <div>
        <NavBar/>
          <Container fluid={true}>
            <Route path='/' component={Workbench}/>
          </Container>
        </div>
      </Router>
    )
  }
}

NavBar.js

import React from 'react';
import {nav} from 'react-bootstrap';

export default class NavBar extends React.Component {

  constructor(props){
    super(props);
    this.state = {
      gameList: [{}],
      gamesVisibility: false
    }
  }
  render() {
    const {gameList, gameVisibility} = this.state;

    return (
      <div className="sidenav">
          <h2 className="sidenav-header"><a href="/">Test project</a></h2>
          <ul>
            <li onClick={() => this.setState({gameVisibility: !gameVisibility})}> <a className="SideNavTitle">Games</a> {this.renderArrow(gameVisibility)} </li>
              {this.renderCollection(gameVisibility, gameList)}
            <li className="SideNavItem"><a>Channel</a></li>
            <li className="SideNavItem"><a>About</a></li>
          </ul>
      </div>
    );
  }

  renderCollection(visibility, collection){
      if (visibility){
          return collection.map((game) => <li id = 'test' className="SideNavSubItem"><a>{game.name}</a></li>)
      }
      else{
        return;
      }
  }

  renderArrow(visibility){
    if (visibility){
      return <i className="fa fa-arrow-down" aria-hidden="true" style={{color: 'white'}}/>
    }
    else{
      return <i className="fa fa-arrow-right" aria-hidden="true" style={{color: 'white'}}/>
    }
  }

}

我使用heroku run bashcat NavBar.js 来确认我的文件在heroku 上,正如this 帖子中所建议的那样。这有点奇怪,因为代码在本地完美运行

编辑:Heroku 上的构建成功,当我尝试加载页面时会显示这些错误。

【问题讨论】:

标签: javascript reactjs meteor heroku


【解决方案1】:

经过一番搜索,我发现在 heroku 上,我有一个 Component 文件夹和一个 component 文件夹。不知道为什么,因为我的流星项目中只有 1 个文件夹组件。使用heroku run bash 查找我的问题。

【讨论】:

    【解决方案2】:

    我假设您的项目文件夹包含三个子文件夹(客户端、组件、服务器)。在你的 main.js 文件中使用:

    import App from '../component/App'

    您使用的是单个“。”它搜索服务器文件夹中的组件文件夹。 你需要用双“。”遍历回来

    【讨论】:

    • 问题依旧吗? @Gleyak iHope
    • 我有 2 个子文件夹(客户端和服务器)组件是客户端的子文件夹。我仍然尝试了您的解决方案,因为我迷路了,一切都只能提供帮助,但它没有用。正如我所说,我的项目在本地运行良好,所以我很确定我的代码没问题。谢谢你的尝试! :)
    猜你喜欢
    • 2015-09-21
    • 2016-07-31
    • 2021-06-17
    • 2016-09-05
    • 1970-01-01
    • 2011-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多