Module not found Error when uploading code to server (React Js, Tailwind CSS, render.com)

huangapple go评论52阅读模式
英文:

Module not found Error when uploading code to server (React Js, Tailwind CSS, render.com)

问题

当我在本地主机上运行我的程序时,没有错误,它可以完美运行。但一旦我将它上传到render.com服务器并添加Tailwind CSS到我的项目后,它无法构建,因为出现以下错误:

找不到模块: 错误: 无法解析 '/opt/render/project/src/src/pages' 目录下的 '../components/Navbar.js'

我已经检查了我的导入语句,它们似乎都是正确的。我还尝试了检查与我添加的Tailwind相关的所有内容,它们都是有道理的。我怀疑问题可能出在tailwind配置文件,也许它在构建时忽略了我的组件?

tailwind.config.js

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./src/**/*.{js,jsx,ts,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
  resolve: {
    extensions: ['.js', '.jsx', '.ts', '.tsx'],
  },
}

这是一个导入Navbar的页面(可能是问题所在?)

import Navbar from "../components/Navbar.js"; 
function Home() {   
    return (     
        <div className="App">         
            <Navbar/>     
        </div>   
    ); 
}

我已经尝试了所有其他类似的Stack Overflow问题,但没有一个解决了我的问题。我还尝试了将我的导入更改为.js,检查导入中的不可见空格、大小写等,还尝试了更改我的Tailwind CSS文件。

这是我的package.json文件:

{
  "name": "ratemyjudge.com",
  "version": "0.1.0",
  "private": false,
  "dependencies": {
    "@emotion/react": "^11.10.5",
    "@emotion/styled": "^11.10.5",
    "@material-ui/core": "^4.12.4",
    "@material-ui/icons": "^4.11.3",
    "@mui/joy": "^5.0.0-alpha.63",
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "firebase": "^9.15.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-icons": "^4.2.0",
    "react-rangeslider": "^2.2.0",
    "react-router-dom": "^6.7.0",
    "react-scripts": "5.0.1",
    "react-toastify": "^9.1.1",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "gh-pages": "^5.0.0",
    "tailwindcss": "^3.2.6"
  }
}

这是我的整个存储库链接:https://github.com/shreybirmiwal/ratemyjudge
非常感谢你的帮助。

英文:

When I run my program in local host, I get no errors, and it works perfectly. As soon as I uploaded to render.com server following adding Tailwind css to my project, It fails to build because

Module not found: Error: Can&#39;t resolve &#39;../components/Navbar.js&#39; in &#39;/opt/render/project/src/src/pages&#39;

I have checked my import statements and they all seem to be correct. I have also tried checking everything related to Tailwind that I added, and they all make sense. I have a suspicion the problem may be with the tailwind config file because maybe it is ignoring my component on the build?

tailwind.config.js

/** @type {import(&#39;tailwindcss&#39;).Config} */
module.exports = {
  content: [
    &quot;./src/**/*.{js,jsx,ts,tsx}&quot;,
  ],
  theme: {
    extend: {},
  },
  plugins: [],
  resolve: {
    extensions: [&#39;.js&#39;, &#39;.jsx&#39;, &#39;.ts&#39;, &#39;.tsx&#39;],
  },
}

Module not found Error when uploading code to server (React Js, Tailwind CSS, render.com)

Here is a page that imports Navbar (maybe the issue?)

import Navbar from &quot;../components/Navbar.js&quot;; 
function Home() {   
    return (     
        &lt;div className=&quot;App&quot;&gt;         
            &lt;Navbar/&gt;     
        &lt;/div&gt;   
    ); 
} 

I have tried all the other stack overflow similar questions but none of them worked, I have tried changing my imports to .js, checking my imports for invisible spaces, upper and lower case, I have also tried changing my tailwind css file.

this is my package.json file

{
  &quot;name&quot;: &quot;ratemyjudge.com&quot;,
  &quot;version&quot;: &quot;0.1.0&quot;,
  &quot;private&quot;: false,
  &quot;dependencies&quot;: {
    &quot;@emotion/react&quot;: &quot;^11.10.5&quot;,
    &quot;@emotion/styled&quot;: &quot;^11.10.5&quot;,
    &quot;@material-ui/core&quot;: &quot;^4.12.4&quot;,
    &quot;@material-ui/icons&quot;: &quot;^4.11.3&quot;,
    &quot;@mui/joy&quot;: &quot;^5.0.0-alpha.63&quot;,
    &quot;@testing-library/jest-dom&quot;: &quot;^5.16.5&quot;,
    &quot;@testing-library/react&quot;: &quot;^13.4.0&quot;,
    &quot;@testing-library/user-event&quot;: &quot;^13.5.0&quot;,
    &quot;firebase&quot;: &quot;^9.15.0&quot;,
    &quot;react&quot;: &quot;^18.2.0&quot;,
    &quot;react-dom&quot;: &quot;^18.2.0&quot;,
    &quot;react-icons&quot;: &quot;^4.2.0&quot;,
    &quot;react-rangeslider&quot;: &quot;^2.2.0&quot;,
    &quot;react-router-dom&quot;: &quot;^6.7.0&quot;,
    &quot;react-scripts&quot;: &quot;5.0.1&quot;,
    &quot;react-toastify&quot;: &quot;^9.1.1&quot;,
    &quot;web-vitals&quot;: &quot;^2.1.4&quot;
  },
  &quot;scripts&quot;: {
    &quot;start&quot;: &quot;react-scripts start&quot;,
    &quot;build&quot;: &quot;react-scripts build&quot;,
    &quot;test&quot;: &quot;react-scripts test&quot;,
    &quot;eject&quot;: &quot;react-scripts eject&quot;
  },
  &quot;eslintConfig&quot;: {
    &quot;extends&quot;: [
      &quot;react-app&quot;,
      &quot;react-app/jest&quot;
    ]
  },
  &quot;browserslist&quot;: {
    &quot;production&quot;: [
      &quot;&gt;0.2%&quot;,
      &quot;not dead&quot;,
      &quot;not op_mini all&quot;
    ],
    &quot;development&quot;: [
      &quot;last 1 chrome version&quot;,
      &quot;last 1 firefox version&quot;,
      &quot;last 1 safari version&quot;
    ]
  },
  &quot;devDependencies&quot;: {
    &quot;gh-pages&quot;: &quot;^5.0.0&quot;,
    &quot;tailwindcss&quot;: &quot;^3.2.6&quot;
  }
}

This is my entire repo: https://github.com/shreybirmiwal/ratemyjudge
Thank you so much for your help

答案1

得分: 0

这是一个相当奇怪的问题,我之前在一些项目中遇到过!

我认为你已将“components”文件夹重命名为“Components”或反之亦然。Git在识别这种重命名方面存在问题,并且无法跟踪它!

我建议你手动重命名导入并尝试一下!

英文:

This is a pretty weird issue that I have encountered previously in some of my projects!

I believe you renamed your "components" folder to "Components" or vice versa. Git has trouble recognising this rename and does not track it well!

I'd suggest you manually rename the imports and try!

huangapple
  • 本文由 发表于 2023年2月14日 21:49:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75448793.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定