1

I recently deleted my node_modules folder from my react app and ran npm install with the following package.json:

{
  "name": "test-react-app",
  "version": "1.0.0",
  "private": true,
  "description": "test",
  "main": "src/index.js",
  "dependencies": {
    "body-parser": "^1.18.2",
    "express": "^4.16.2",
    "material-ui": "^0.19.4",
    "node-sass-chokidar": "0.0.3",
    "npm-run-all": "^4.1.1",
    "react": "^15.6.2",
    "react-dom": "^15.6.2",
    "react-router": "^4.2.0",
    "react-router-dom": "^4.2.2",
    "react-scripts": "^1.0.10"
  },
  "scripts": {
    "build-css": "node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/",
    "watch-css": "npm run build-css && node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/ --watch --recursive",
    "start-js": "react-scripts start",
    "start": "npm-run-all -p watch-css start-js",
    "build": "npm run build-css && react-scripts build webpack -p",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "devDependencies": {
    "node-sass": "^4.5.3",
    "sass-loader": "^6.0.6",
    "babel-core": "6.17.0",
    "babel-loader": "6.2.5",
    "babel-preset-es2015": "6.16.0",
    "css-loader": "0.25.0",
    "file-loader": "0.9.0",
    "html-loader": "0.4.4",
    "html-webpack-plugin": "2.24.0",
    "material-ui": "^0.19.4",
    "open-browser-webpack-plugin": "0.0.2",
    "rimraf": "2.5.4",
    "style-loader": "0.13.1",
    "webpack": "^3.7.1",
    "webpack-dashboard": "0.2.0",
    "webpack-dev-server": "1.16.2"
  }
}

After doing so, I now run into the following console error after running npm start:

Uncaught Error: Cannot find module "."
    at webpackMissingModule (source-map-generator.js:8)
    at Object.<anonymous> (source-map-generator.js:8)
    at Object../node_modules/source-map/lib/source-map/source-map-generator.js (source-map-generator.js:399)
    at __webpack_require__ (bootstrap bf59d56b93d65ff61848:669)
    at fn (bootstrap bf59d56b93d65ff61848:87)
    at Object../node_modules/source-map/lib/source-map.js (source-map.js:6)
    at __webpack_require__ (bootstrap bf59d56b93d65ff61848:669)
    at fn (bootstrap bf59d56b93d65ff61848:87)
    at Object../node_modules/react-error-overlay/lib/utils/getSourceMap.js (getSourceMap.js:1)
    at __webpack_require__ (bootstrap bf59d56b93d65ff61848:669)

Here is my App.js:

import React, { Component } from 'react';
import { Switch, Route } from 'react-router';
import { PrivateRoute } from './utilities/PrivateRoute'; 
import Home from './components/screens/Home/Home';
import Dashboard from './components/containers/Dashboard/Dashboard';
import Menu from './components/containers/Menu/Menu';
import Login from './components/screens/Login/Login';
import Registration from './components/screens/Registration/Registration';
import NoMatch from './components/screens/NoMatch/NoMatch';
import './styles/main.css';
import logo from './assets/img/logo/logo.svg';

class App extends Component {
  render() {
    return (
      <div className="app">
        <div className="flex-container">
          <img src={logo} alt="logo"/>
        </div>
        <Switch>
          <Route exact path="/" component={Login} />
          <Route path="/login" component={Login} />
          <Route path="/registration" component={Registration}/>
          <PrivateRoute path="/home" component={Home}/>
          <PrivateRoute path="/dashboard" component={Dashboard}/>
          <PrivateRoute path="/menu" component={Menu}/>
          <Route component={NoMatch}/>
        </Switch>
      </div>
    );
  }
}

export default App;

Here is my webpack.config.js:

const path              = require('path');
const webpack           = require('webpack');
const htmlPlugin        = require('html-webpack-plugin');
const openBrowserPlugin = require('open-browser-webpack-plugin'); 
const dashboardPlugin   = require('webpack-dashboard/plugin');
const autoprefixer      = require('autoprefixer'); 

const PATHS = {
  app: path.join(__dirname, 'src'),
  images:path.join(__dirname,'src/assets/'),
  build: path.join(__dirname, 'dist')
};

const options = {
  host:'localhost',
  port:'1234'
};

module.exports = {
  entry: {
    app: path.join(PATHS.app,'index.js')
  },
  output: {
    path: PATHS.build,
    filename: 'bundle.[hash].js'
  },
  devServer: {
      historyApiFallback: true,
      hot: true,
      inline: true,
      stats: 'errors-only',
      host: options.host,
      port: options.port 
    },
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel-loader',
        query: {
          cacheDirectory: true,
          presets: ['es2015']
        }
      },
      { test: /\.css$/, loader: 'style-loader!css-loader' },
      {
        test: /\.(ico|jpg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,        
        loader: 'file',
        query: {
          name: '[path][name].[ext]'
        }
      },      
    ]
  },
  plugins:[
    new dashboardPlugin(),
    new webpack.HotModuleReplacementPlugin({
        multiStep: true
    }),
    new htmlPlugin({
      template:path.join(PATHS.app,'index.html'),
      inject:'body'
    }),
    new openBrowserPlugin({
      url: `http://${options.host}:${options.port}`
    })
  ]
};

Here are my current environment settings:

  • npm version 5.5.1
  • node version 7.3.0
  • Windows 10

Does anyone have any sort of idea what might be the issue? Looking around it seems that the latest version of react-scripts (1.0.14) has a fix, but I am running that after npm install.

9
  • 1
    Your npm version is rather old, can you update to the latest version and try again? npm i -g npm@latest Commented Oct 23, 2017 at 1:16
  • Good call. I updated and edited. My npm version is now 5.5.1. Unfortunately, the issue still persists. Commented Oct 23, 2017 at 1:42
  • I also nuked my node_modules folder and npm installed again to no success :( Commented Oct 23, 2017 at 1:49
  • Alright. Since you’ve updated and the issue persist, we will need to see your webpack.config.js file and perhaps the app.js file as well. Commented Oct 23, 2017 at 1:49
  • I don't have a webpack.config.js in my solution at this time - is it necessary? Commented Oct 23, 2017 at 2:33

1 Answer 1

1

I do not know, but it looks like you have error in your code, you try to import switch and route from wrong package. React-router - 3 version, and react-router-dom - 4 version, so your code should look like below;

import { Switch, Route } from 'react-router-dom';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.