[英]Cannot find local module in typescript error on node
I'm new to typescript my problem is that local module i created I can't use我是 typescript 的新手,我的问题是我创建的本地模块无法使用
./route/routes.ts ./route/routes.ts
import routes from 'next-routes'
let route = new routes()
route.add('index', '/:name')
export default route
and in my server.ts在我的 server.ts 中
import route from "./route/routes"
but when i run npm run start
then i get the following error但是当我运行
npm run start
然后我得到以下错误
Cannot find module "./route/routes"
找不到模块“./route/routes”
this is my tsconfig.json这是我的 tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"noImplicitAny": false
},
"exclude": [
"node_modules"
],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
]
}
and my package.json和我的 package.json
{
"name": "Test",
"version": "1.0.0",
"description": "",
"main": "babel-node --presets es2015 server.ts",
"scripts": {
"dev": "node server.ts",
"build": "next build",
"postinstall": "npm run build",
"start": "NODE_ENV=production babel-node --presets es2015 server.ts"
},
"author": "Test",
"license": "",
"dependencies": {
"@zeit/next-sass": "^1.0.1",
"express": "^4.17.1",
"next": "^9.0.5",
"next-routes": "^1.4.2",
"node-sass": "^4.12.0",
"react": "^16.9.0",
"react-dom": "^16.9.0"
},
"devDependencies": {
"@types/express": "^4.17.11",
"@types/node": "^14.14.31",
"@types/react": "^17.0.2",
"babel": "^6.23.0",
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"nextjs-sitemap-generator": "^0.1.1",
"nodemon": "^2.0.7",
"typescript": "^4.2.2"
}
}
i'm getting error since i migrate to typescript from js我从 js 迁移到 typescript 后出现错误
Note: I try to find solution search online seems i can't find really good one注意:我尝试在网上寻找解决方案搜索似乎找不到真正好的解决方案
Thanks谢谢
Try moving routes.ts, to wherever your server.ts file is present, update the import statement, and see if it works尝试将 routes.ts 移动到 server.ts 文件所在的任何位置,更新 import 语句,看看它是否有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.