I'm new to typescript my problem is that local module i created I can't use
./route/routes.ts
import routes from 'next-routes'
let route = new routes()
route.add('index', '/:name')
export default route
and in my server.ts
import route from "./route/routes"
but when i run npm run start
then i get the following error
Cannot find module "./route/routes"
this is my 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
{
"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
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
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.