git合并冲突后出现npm错误

时间:2018-06-19 20:14:57

标签: git reactjs npm package.json

所以,我正在使用React,确切地说是create-react-app。

主要问题:如何使React恢复工作?我几乎是npm / React的初学者,所以我不知道从哪里开始进行故障排除。

手动合并20天前创建的分支后,这导致了一些合并冲突,启动React开发服务器(npm start)时出现以下错误。

其中一个合并冲突是在package.json中,因此这可能是问题起源的地方。我将package.json文件发布在底部。

Module not found: Can't resolve 'styled-components' in 'C:\Users\riksch\Documents\MEGAsync\projects\Current\greenery-marketplace\frontend\src'

因此,我尝试重新安装它。还是一样的错误。

然后我搜索了一些,并找到了列出已安装软件包的方法,所以我运行了:

npm list --depth=0

这显示了一些错误:

+-- axios@0.18.0
+-- jquery@3.3.1
+-- js-cookie@2.2.0
+-- UNMET PEER DEPENDENCY react@16.2.0
+-- react-dom@16.2.0
+-- react-form@3.5.5
+-- react-intl@2.4.0
+-- react-route@1.0.3
+-- react-router-dom@4.2.2
+-- react-scripts@1.1.1
+-- react-strap@0.0.1
+-- reactstrap@6.0.1
`-- UNMET DEPENDENCY styled-components@^3.3.2

npm ERR! peer dep missing: react@^0.13.3 || ^0.14.0-rc1, required by react-route@1.0.3
npm ERR! missing: styled-components@^3.3.2, required by frontend@0.1.0
npm ERR! peer dep missing: ajv@^6.0.0, required by ajv-keywords@3.1.0

然后我尝试更新npm,希望能有所帮助。

npm update -g --verbose

我还尝试将包以不同的顺序放在package.json文件中。这似乎没有帮助。然后我尝试卸载样式化组件,但这又出现了另一个错误:

npm ERR! Unexpected string in JSON at position 332738

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\riksch\AppData\Roaming\npm-cache\_logs\2018-06-19T19_56_05_969Z-debug.log

再次尝试安装样式化组件会给我以下信息:

npm错误! JSON中意外的字符串,位置332738

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\riksch\AppData\Roaming\npm-cache\_logs\2018-06-19T19_56_21_076Z-debug.log
PS C:\Users\riksch\Documents\MEGAsync\projects\Current\greenery-marketplace\frontend>

package.json:

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.18.0",
    "jquery": "^3.3.1",
    "js-cookie": "^2.2.0",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-form": "^3.5.5",
    "react-intl": "^2.4.0",
    "react-route": "^1.0.3",
    "react-router-dom": "^4.2.2",
    "react-scripts": "1.1.1",
    "styled-components": "^3.3.2",
    "react-strap": "0.0.1",
    "reactstrap": "^6.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}
具有无法解决的合并冲突的

package.json:

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.18.0",
    "jquery": "^3.3.1",
    "js-cookie": "^2.2.0",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-form": "^3.5.5",
    "react-intl": "^2.4.0",
    "react-route": "^1.0.3",
    "react-router-dom": "^4.2.2",
    "react-scripts": "1.1.1",
<<<<<<< HEAD
    "styled-components": "^3.3.2"
=======
    "react-strap": "0.0.1",
>>>>>>> contact-form
    "reactstrap": "^6.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

现在,我不想把事情弄得更糟。所以我在这里发布我的问题:

如何使React恢复工作?我几乎是npm / React的初学者,所以我不知道从哪里开始进行故障排除。

1 个答案:

答案 0 :(得分:0)

我解决了这个错误,尽管我猜不是很优雅。

我只是使用'create-react-app'创建了一个新的React环境。然后,我使用旧的package.json在新环境中安装所有必需的软件包/依赖项。

之后,我将/ public和/ src目录从旧环境复制到新环境(在新的React环境中覆盖目录)。

此后一切都很好。