无法在节点的typescript错误中找到本地模块



我是新的typescript我的问题是,我创建的本地模块,我不能使用

。/线路/routes.ts

import routes from 'next-routes'

let route = new routes()
route.add('index', '/:name')
export default route

和my server.ts

import route from "./route/routes"

但是当我运行npm run start时,我得到以下错误

找不到模块"/route/routes">

我的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"
]
}

和my 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"
}
}

我得到错误,因为我迁移到typescript从js

注意:我试着在网上寻找解决方案,似乎我找不到真正好的一个

感谢

尝试移动路线。不管你的服务器在哪里。如果存在Ts文件,则更新import语句,并查看它是否有效

最新更新