简体   繁体   English

错误:找不到模块; 反应项目中的 Typescript 错误

[英]Error: Cannot find module; Typescript error in react project

I have a.js file called load_routes.js file in the node_express folder.我在 node_express 文件夹中有一个名为 load_routes.js 的 .js 文件。 This load_routes.js file loads all my routes for the project.这个 load_routes.js 文件加载了我的项目的所有路线。 I have a package.json file in which the load_routes.js is used to load the routes.我有一个 package.json 文件,其中 load_routes.js 用于加载路由。 So, this part was working fine, until I changed the file extension of load_routes.js file to.ts file.所以,这部分工作正常,直到我将 load_routes.js 文件的文件扩展名更改为 .ts 文件。 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.并且 node_express 文件夹与 package.json 文件同级或存在。

package.json file: package.json 文件:

"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.文件 load_routes.ts 肯定在那里。 The path to that file seems correct as it worked when it was a.js file.该文件的路径似乎是正确的,因为它是一个 .js 文件。 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. require调用将自动找出正确的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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