npm install从package-lock.json中删除React路由器

时间:2018-07-03 18:30:44

标签: javascript reactjs npm react-router

当我从我的应用程序中删除node_modules,然后运行npm install时,我的package-lock.json更改了,而react-router也从其中删除了。我收到未找到模块react-router的错误。在它完美运行之前。这是我的webpack-config:

`module.exports = {
  entry: ['whatwg-fetch', "./js/app.jsx"],
  output: { filename: "./js/out.js" },
  watch: true,
  devServer: {
  inline: true,
  contentBase: './',
  port: 3001
  },
  module: {
  loaders: [
      {
      test: /\.jsx$/, exclude: /node_modules/,
      loader: 'babel-loader',
      query: { presets: ['es2015', 'stage-2', 'react'] }
      },
      {
      test: /\.css$/,
      loader: 'style-loader!css-loader'
      }
    ]
  }
}`

和我的package.json

`{
  "name": "test",
  "version": "1.0.0",
  "description": "test",
  "main": "webpack.config.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "./node_modules/.bin/webpack-dev-server --hot"
  },
  "author": "test",
  "license": "ISC",
  "": {
    "babel-core": "^6.23.1",
    "babel-loader": "^6.3.2",
    "babel-preset-es2015": "^6.22.0",
    "babel-preset-react": "^6.23.0",
    "webpack": "^2.2.1"
  },
  "dependencies": {
    "react": "^15.4.0",
    "react-dom": "^15.4.0",
    "whatwg-fetch": "^2.0.3"
  },
  "devDependencies": {
    "babel-core": "^6.23.1",
    "babel-loader": "^6.3.2",
    "babel-preset-es2015": "^6.22.0",
    "babel-preset-react": "^6.23.0",
    "babel-preset-stage-2": "^6.24.1",
    "css-loader": "^0.28.11",
    "style-loader": "^0.21.0",
    "webpack": "^2.2.1",
    "webpack-dev-server": "^2.6.1"
  }
}
`

2 个答案:

答案 0 :(得分:1)

在删除react-router-dom之前,您很可能只是安装了dependencies而未将其添加到node_modules中。尝试安装它并将其添加到您的dependencies中,它将再次起作用。

npm i -S react-router-dom

答案 1 :(得分:0)

由于删除了node_modules,因此卸载了反应路由器dom,因此必须重新安装react-router

  1. npm install --save react-router-dom