简体   繁体   English

Heroku找不到任何模块

[英]Heroku cannot find any module

I'm trying to develop a webapp using meteor and Heroku. 我正在尝试使用流星和Heroku开发一个webapp。 When I run my code locally everything is fine, but as soon as I deploy it on Heroku, i get: 当我在本地运行代码时,一切都很好,但是将其部署到Heroku上后,我得到:

Cannot find module './navbar/NavBar.js' 找不到模块'./navbar/NavBar.js'

or if I get rid of the NavBar in my code: 或者如果我在代码中放弃了NavBar:

Cannot find module './component/App' 找不到模块“ ./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 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 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 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. 我使用heroku run bash以及cat NavBar.js来确认我的文件是否在帖子中所建议的heroku上。 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. 编辑:Heroku上的构建成功,当我尝试加载页面时显示这些错误。

With some searching, I found that on heroku, I had a Component folder and a component folder. 经过一些搜索,我发现在heroku上,我有一个Component文件夹和一个component文件夹。 Not sure why since there is only 1 folder component in my meteor project. 不知道为什么,因为我的流星项目中只有1个文件夹组件。 Used heroku run bash to find what was my problem. heroku run bash查找我的问题。

I am assuming your project folder contains three sub folders(client,component, server). 我假设您的项目文件夹包含三个子文件夹(客户端,组件,服务器)。 In your main.js file use: 在您的main.js文件中使用:

import App from '../component/App'

you are using single "." 您正在使用单个“。” which searches the component folder in server folder. 在服务器文件夹中搜索组件文件夹。 you need to traverse back with double "." 您需要使用双“”来回退。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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