简体   繁体   中英

Heroku cannot find any module

I'm trying to develop a webapp using meteor and Heroku. When I run my code locally everything is fine, but as soon as I deploy it on Heroku, i get:

Cannot find module './navbar/NavBar.js'

or if I get rid of the NavBar in my code:

Cannot find module './component/App'

My project folder looks like:

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

  Server
    main.js

And this is my code:

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'}}/>
    }
  }

}

I used heroku run bash along with cat NavBar.js to confirm that my file was on heroku as suggested in this post. Its kind of weird since the code work perfectly locally

Edit: The build on Heroku is successful, these errors show when I try to load my page.

With some searching, I found that on heroku, I had a Component folder and a component folder. Not sure why since there is only 1 folder component in my meteor project. Used heroku run bash to find what was my problem.

I am assuming your project folder contains three sub folders(client,component, server). In your main.js file use:

import App from '../component/App'

you are using single "." which searches the component folder in server folder. you need to traverse back with double "."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM