I am trying to build a nuxtjs app with command "npm run build," which is executing "nuxt build."
However, the build fails and it looks like nuxt doesn't know how to compile Typescript code. But the funny thing is that the "npm run dev" command works without any problems and the app works. Just the production build is failing.
I noticed that if I remove the lang="ts" from the script tag in my single file components, the error is gone, but of course, the typescript code doesn't compile and other errors occur. I tried with various tsconfig.json configurations, but none is working. I have typescript and ts-loader modules included in dependencies in package.json file.
"ts-loader": "^5.3.3",
"typescript": "^3.3.3",
This is an example of the error message which I receive when I run "npm run build"
ERROR in ./pages/index.vue?vue&type=script&lang=ts& (./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib??ref--0-2!./node_modules/ts-loader??ref--0-3!./node_modules/babel-loader/lib??ref--4-0!./node_modules/ts-loader??ref--4-1!./node_modules/vue-loader/lib??vue-loader-options!./pages/index.vue?vue&type=script&lang=ts&)
Module build failed (from ./node_modules/thread-loader/dist/cjs.js):
Thread Loader (Worker 4)
Cannot read property 'errors' of undefined
at successfulTypeScriptInstance (../node_modules/ts-loader/dist/instances.js:90:28)
at Object.getTypeScriptInstance (../node_modules/ts-loader/dist/instances.js:34:12)
at Object.loader (../node_modules/ts-loader/dist/index.js:17:41)
@ ./pages/index.vue?vue&type=script&lang=ts& 1:0-404 1:420-423 1:425-826 1:425-826
@ ./pages/index.vue
@ ./.nuxt/router.js
@ ./.nuxt/index.js
@ ./.nuxt/client.js
@ multi ./.nuxt/client.js
This is my tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"es2015"
],
"module": "es2015",
"moduleResolution": "node",
"experimentalDecorators": true,
"noImplicitAny": false,
"noImplicitThis": false,
"strictNullChecks": true,
"removeComments": true,
"suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true,
"allowJs": true,
"baseUrl": ".",
"paths": {
"~/*": [
"./*"
]
},
"noUnusedLocals": true,
"resolveJsonModule": true,
"esModuleInterop": true
}
}
Does anybody have any ideas how to make NuxtJs work with Typescript for production builds and not only for development?
Thanks