[英]Git/node getting stuck on old .js -file version
我遇到了一個奇怪的問題,git/node 卡住了使用舊版本的 .js 文件。 每隔一段時間保存更改后(到目前為止,僅當代碼中有一些錯誤時,通常在合並沖突之后),文件在構建應用程序時會以某種方式卡在舊版本中。 一切看起來都很好,VSCode 更改了文件並顯示得很好,但是在嘗試構建應用程序時,構建過程(開發和生產)使用舊的文件版本,其中存在錯誤。
同樣的事情在 Win10 和 MacOs 上都發生了。
我找到了 2 種方法來解決這個問題(都只是解決方法)
以下是示例文件:
InfoComponents.js(這個有錯誤)
import React from 'react';
import Typography from '@material-ui/core/Typography';
import Battery from '@navigil/shared/src/components/SVGs/Battery';
import Box from '@navigil/shared/src/components/Box/Box';
import InfoBadge from './InfoBadge';
const batteryStatus = [80, 50, 15, 5];
const InfoComponents = ({ badges }) => (
<>
<Typography variant='h4'>Status / Warnings / Alarms</Typography>
<Box>
{badges.map((badge, index) => {
const { badgeProps, imageProps, imageComponent: Image } = badge;
return (
<InfoBadge key={index} {...badgeProps}>
<Image {...imageProps} />
</InfoBadge>
);
})}
</Box>
</>
);
export default InfoComponents;
Dashboard.js(這會導入 InfoComponents)
import React from 'react';
import Typography from '@material-ui/core/Typography';
import styled from 'styled-components';
import Battery from '@navigil/shared/src/components/SVGs/Battery';
import Box from '@navigil/shared/src/components/Box/Box';
import Button from '@navigil/shared/src/styledTheme/Components/Button';
import InfoComponents from './InfoComponents';
import { badges } from './testVariables';
const StyledButton = styled(Button)`
max-width: 100px;
`;
const NewWatchDashboard = () => (
<>
<InfoComponents badges={badges} />
</>
);
export default NewWatchDashboard;
這是我在構建失敗時收到的解析錯誤:
./src/InfoComponents/Dashboard.js
Line 7:28: Parse errors in imported module './InfoComponents': Line 14: Unexpected token
12 | <Box>
13 | {badges.map((badge, index) => ({
> 14 | <InfoBadge key={index} {...badgeProps}>
| ^
15 | <Image {...imageProps} />
16 | </InfoBadge>;
17 | }))} (14:9) import/namespace
Line 7:28: Parse errors in imported module './InfoComponents': Line 14: Unexpected token
12 | <Box>
13 | {badges.map((badge, index) => ({
> 14 | <InfoBadge key={index} {...badgeProps}>
| ^
15 | <Image {...imageProps} />
16 | </InfoBadge>;
17 | }))} (14:9) import/default
從上面可以看出,InfoComponents.js 中的代碼與錯誤消息中的代碼不匹配。
為此創建一個沙箱有點困難,因為如果我從頭開始創建所有這些,一切都很好。 所以它顯然是 Git 的一個問題。 任何想法可能導致這種情況以及如何防止它發生? 任何想法如何在發生時輕松解決這個問題?
-尤卡
問題很可能出在您本地的 Git 工作樹上。 嘗試以下方法:
#Copy the code from `InfoComponents.js` to some other file.
git rm --cached InfoComponents.js
#Commit the change
# add back the file with backed up content
# commit again
這可能會解決問題。
或者
嘗試清理本地git
工作樹: git gc --prune=now
並檢查您的更改是否正確反映。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.