I try to move my project to ts, then this error raise
error TS2306: File '/xxxx/xxxxx/node_modules/nuxt/index.d.ts' is not a module.
here is tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"es5",
"es2015"
],
"module": "es2015",
"moduleResolution": "node",
"allowJs": true,
"experimentalDecorators": true,
//"declaration": true,
"noImplicitAny": false,
"noImplicitThis": false,
"strictNullChecks": true,
"removeComments": true,
"suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
"~": ["./"],
"~assets/*": ["./assets/*"],
"~components/*": ["./components/*"],
"~middleware/*": ["./middleware/*"],
"~pages/*": ["./pages/*"],
"~plugins/*": ["./plugins/*"],
"~static/*": ["./static/*"]
}
}
}
here is server.ts , error on import { Nuxt, Builder } from 'nuxt'
import Koa from 'koa'
import { Nuxt, Builder } from 'nuxt'
import config from '../nuxt.config.js'
const app = new Koa()
const host = process.env.HOST || '127.0.0.1'
const port = parseInt(process.env.PORT || '3000')
config.dev = !(app.env === 'production')
// Instantiate nuxt.js
const nuxt = new Nuxt(config)
// Build in development
if (config.dev) {
const builder = new Builder(nuxt)
builder.build().catch(e => {
console.error(e); // eslint-disable-line no-console
process.exit(1)
})
}
app.use(ctx => {
ctx.status = 200 // koa defaults to 404 when it sees that status is unset
return new Promise((resolve, reject) => {
ctx.res.on('close', resolve)
ctx.res.on('finish', resolve)
nuxt.render(ctx.req, ctx.res, promise => {
// nuxt.render passes a rejected promise into callback on error.
promise.then(resolve).catch(reject)
})
})
})
app.listen(port, host)
console.log('Server listening on ' + host + ':' + port)
and check index.d.ts in node_modules/nuxt/
the content is
//These declarations allow TypeScript to import non-js/ts files without the file extensions (such as .vue files)
declare module "~components/*" {}
declare module "~layouts/*" {}
declare module "~pages/*" {}
declare module "~assets/*" {}
declare module "~static/*" {}
I remove index.d.ts and project can run
I check typescript 2.x doc, It seem that module can't use like this
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c1261">#c1261</a>)</em></sub></div>