0

I have intialized a new project with npx create-react-app. It created a basic file structure. First thing I wanted to do is to create routing (RESTAPI) with express.js. On the screenshot you can see my file structure as well as routing.js file and its content.

The problem I'm facing is that when I try to run express server by using "node routing.js" I get the following error:

internal/modules/cjs/loader.js:797
    throw err;
    ^

Error: Cannot find module 'D:\Informatyka\GitHub\kinocamp\routing.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)  
    at Function.Module._load (internal/modules/cjs/loader.js:687:27)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)
    at internal/main/run_main_module.js:17:11 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

If I use nodemon I get this error:

[nodemon] 2.0.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `react-scripts start routing.js`
'react-scripts' is not recognized as an internal or external command,
operable program or batch file.
[nodemon] app crashed - waiting for file changes before starting...

I tried to install dependencies multiple times (deleted node modules etc), create project from scratch. And nothing works at all. I guess package.json content may be needed so here it is:

"name": "kinocamp",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.4.0",
    "@testing-library/user-event": "^7.2.1",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-scripts": "^3.3.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "nodemon": "^2.0.2"
  }
}

2 Answers 2

1

routing.js is in your src folder: ie. D:\Informatyka\GitHub\kinocamp\src\routing.js

You need to run node src\routing.js

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the answer however there is a problem though. Node says routing.js isn't a module and I cant use import statement there. It's the same error for node and nodemon with src/routing.js. Any clue why it doesnt accept it as a module?
Are you importing 'router.js' anywhere else in your app?
I don't since router.js is going to contain only express.js configuration so the only thing I need is to import the main components that will be rendered when clicking an url in nav bar to routing.js file.
0

Usually, this kind of error occurs when an npm package isn't installed globally.

Try to install react-scripts globally

OR

start the app by typing one of the defined script commands in package.json, after you have modified the command to execute locally saved relevant npm package. For example, modify package.json scripts property like so:

"start": "./node_modules/.bin/react-scripts start",

and then, on command line execute npm start

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.