【问题标题】:Failed to compile: Cannot find file './containers/App/App' in './src'编译失败:在“./src”中找不到文件“./containers/App/App”
【发布时间】:2019-09-09 06:36:26
【问题描述】:

我一直很难将 React.js 应用程序推送到 Heroku,因为我不断收到一条包含以下放大信息的构建失败消息。

Heroku 构建控制台:

-----> Build
       Running build

       > veterinfo@0.1.0 build /tmp/build_2456efea678b82d24203cb2e2c7bcbd5
       > react-scripts build

       Creating an optimized production build...
       Failed to compile.

       ./src/index.js
       Cannot find file './containers/App/App' in './src'.

我的 index.js 文件:

import App from './containers/App/App'
import * as serviceWorker from './serviceWorker'
import { BrowserRouter } from 'react-router-dom'
import { Provider } from 'react-redux'
import { createStore, applyMiddleware } from 'redux'
import rootReducer from './reducers'
import { composeWithDevTools } from 'redux-devtools-extension'
import thunk from 'redux-thunk'

const store = createStore(rootReducer, composeWithDevTools(applyMiddleware(thunk)))

const router = (
    <Provider store={store}>
        <BrowserRouter>
            <App />
        </BrowserRouter>
    </Provider>
)

文件结构:

src
  -->containers
    -->App
      -->__snapshots__
      -->App.js
      -->App.scss
      -->App.test.js
  -->index.js

我已尝试删除 node_modules 并重新安装它们, 我试过清除heroku中的构建缓存, 我试过在相对路径中指定App.js, 我尝试在 yml 和 package.json 文件中指定节点版本, Build 在本地通过npm run build, 我尝试将每个组件传递到路由器的位置,我发现所有组件都可以工作,但所有容器都不能(这可能是一个 redux 问题吗?)

我快没主意了:/

【问题讨论】:

  • 尝试将您的代码减少到最低限度,并在 index.js 中简单地显示一个测试组件。如果这不起作用,则可能是您的应用程序的配置。如果它确实有效,然后一个一个地重新添加组件,您很快就会发现问题所在
  • 谢谢,我会试一试的!
  • './components' 工作,但 './containers' 不工作:/

标签: javascript reactjs heroku build


【解决方案1】:

你可以先清除缓存,看看是否有文件被重命名了。

这将缓存整个目录:

git rm -r --cached .

此外,您必须添加、提交和推送更改:

git add .
git commit -am 'Removing cached files'

【讨论】:

  • 这正是我的问题。我重命名了一个文件,显然 git 没有注册我重命名它。删除缓存有效。 +1
【解决方案2】:

containers 重命名为Containers 并将components 重命名为Components

【讨论】:

  • 那么为什么需要重命名呢?
  • 不知道。这对我有用,也许对其他一些人有用。
【解决方案3】:

您可能在提交到 git 后更改了文件名的大小写。您可以通过调用git mv path/app.js path/App.js 来修复它。这会显式更改 git 中的文件名。

【讨论】:

    【解决方案4】:

    当我将目录重命名为 Containers 并将相对路径重命名为 import App from './Containers/App/App' 时,问题已解决

    【讨论】:

      【解决方案5】:

      检查 .gitignore ,可能是您的文件没有被发送到远程存储库

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-06-17
        • 2021-03-07
        • 2020-03-06
        • 1970-01-01
        • 1970-01-01
        • 2019-12-10
        • 2020-10-10
        • 1970-01-01
        相关资源
        最近更新 更多