简体   繁体   中英

Error: Cannot find module; Typescript error in react project

I have a.js file called load_routes.js file in the node_express folder. This load_routes.js file loads all my routes for the project. I have a package.json file in which the load_routes.js is used to load the routes. So, this part was working fine, until I changed the file extension of load_routes.js file to.ts file. I started getting

Error: Cannot find module '/*****/***/****/****/****/node_express/load_routes.ts'

I have not changed the location of the files. And the node_express folder is a sibling or present at the same level as that of package.json file.

package.json file:

"scripts": {
    "build": "react-scripts build && echo \"const version='$(git rev-parse HEAD)'; module.exports=version\" > ./node_express/version/release-version.js",
    "eject": "react-scripts eject",
    "server": "NODE_ENV=localhost PORT=**** node --max-http-header-size 81000 ./node_express/load_routes.ts",
    "start": "react-scripts start",
  },

Can someone help me with this. The file load_routes.ts is for sure there. The path to that file seems correct as it worked when it was a.js file. Why do I get this error? I am stuck on this for quite some time. Any help would be appreciated.

Don't specify the file extension at all. The require call will figure out the right file automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM