- nuxt: 2.6.2
- node: 16.5.0
- koa: 2.7.0
Here is the content of my package.json
file :
{
...
"scripts": {
"dev": "cross-env NODE_ENV=development nodemon server/index.ts --watch server --exec babel-node --presets @babel/preset-env"
}
}
Observations:
Upon running the command `yarn dev`, the following events unfold:
The KOA server successfully compiles and runs, prompting me with the question "Are you interested in participating?". I select "yes".
Subsequently, as the Nuxt web server begins to compile, an error message stating "ERROR Failed to compile with 3 errors" appears on the console. Upon investigation, it becomes evident that these errors are related to TypeScript usage within my Vue pages or Components, such as:
Module parse failed: Unexpected character '@' (11:0) friendly-errors 23:08:49
File was processed with these loaders:
* ./node_modules/vue-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| import {Vue, Component} from 'vue-property-decorator';
|
> @Component
| export default class GlobalLayout extends Vue {
|
friendly-errors 23:08:49
@ ./layouts/GlobalLayout.vue?vue&type=script&lang=ts& 1:0-124 1:140-143 1:145-266 1:145-266
@ ./layouts/GlobalLayout.vue
@ ./.nuxt/App.js
@ ./.nuxt/index.js
@ ./.nuxt/client.js
@ multi ./node_modules/eventsource-polyfill/dist/browserify-eventsource.js (webpack)-hot-middleware/client.js?reload=true&timeout=30000&ansiColors=&overlayStyles=&path=%2F__webpack_hmr%2Fclient&name=client ./.nuxt/client.js
- Eventually, the console is able to display the output of console.log statements written in `server/index.ts`. This raises the question whether using `nodemon` instead of `nuxt` to start the entire server could potentially resolve some of the TypeScript compilation errors encountered. Surprisingly, running `nuxt` directly results in successful compilation without any errors, whereas integrating Koa and modifying the development command leads to these issues.
Exploring Solutions
In an attempt to address this issue, I searched for a similar repository online and stumbled upon one that utilizes nuxt + ts + koa in a manner akin to mine.
https://github.com/negibouze/nuxt-koa-ts
I cloned this repository and reproduced the same errors on my local machine. Feel free to clone and investigate further.