Trying to create a Nuxt.js app by using the "npm run build" command, specifically executing "nuxt build," has become quite challenging for me.
Sadly, the production build continuously fails because it seems like Nuxt is struggling with compiling Typescript code. Surprisingly, everything works smoothly when I use the "npm run dev" command, and the application runs without any issues. It's just the production build that poses problems.
I've experimented with different configurations in my tsconfig.json file, but none of them seem to solve the issue. Both typescript and ts-loader modules are properly included in the dependencies section of my package.json file as well.
"ts-loader": "^5.3.3",
"typescript": "^3.3.3",
An error message similar to the one below surfaces whenever I attempt to execute "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 snippet showcases the content of my tsconfig.json file
{
"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
}
}
If anyone has suggestions on how to resolve the compatibility issues between Nuxt.js and Typescript during production builds, your input would be greatly appreciated.
Thank you!