`ssr:serve` script doesn't work with Vue 2 & TypeScript
Description
ssr:serve NPM script doesn't work with Vue 2 & TypeScript app created with Vue CLI.
Reproduction steps
- Create a new Vue (2.x) app with TS support, using the Vue CLI:
- Run the following command:
vue create vue2-uvue:- Please pick a preset: Manually select features.
- Check the features needed for your project::
- Choose Vue version
- Babel
- TypeScript
- Choose a version of Vue.js that you want to start the project with: 2.x.
- Use class-style component syntax? Yes.
- Use Babel alongside TypeScript? Yes.
- Where do you prefer placing config for Babel, ESLint, etc.? In dedicated config files.
- Save this as a preset for future projects? No.
- Run the following command:
- Check if the app has been bootstrapped successfully:
- Run the following command:
npm run serve.- Expected output:
DONE Compiled successfully in Xms \n No type errors found \n Version: typescript 3.9.9 \n Time: Xms \n App running at: \n - Local: http://localhost:8080/ \n - Network: http://192.168.X.X:8080/ \n Note that the development build is not optimized. To create a production build, run npm run build. - Expected state of the browser when asked to open
http://localhost:8080/:
- Expected output:
- Run the following command:
- Add Universal Vue to the project
- Run the following command:
vue add @uvue/ssr:- Install UVue plugins?
- Async Data method
- Middleware system
- Error handler
- Install server plugins?
- GZIP compression
- Server error page
- Static files serving
- Modern build
- Do you want to use Docker to deploy your app? No.
- Install UVue plugins?
- Expected output:
DONE ssr \n UVue installed, please read this before starting: \n https://universal-vue.github.io/docs/guide/post-install.html#post-installation-notes
- Run the following command:
- Check if the UVue has been installed successfully:
- Run the following command:
npm run ssr:serve.
- Run the following command:
Expected behavior
Console should produce following output:
DONE
Compiled successfully in XXXms
Server is running: http://localhost:8080
Type "rs" to restart server
No type errors found
Version: typescript 3.9.9
Time: XXms
After asked to open the URL http://localhost:8080/, the browser should look exactly the same as it looks after running the command npm run serve.
Actual behavior
The browser can't locate the server/resources/whatever we're asking it for:
-
Google Chrome Dev:

-
Firefox Developer Edition:

-
Sizzy:

Additional thoughts
- The
npm run servecommand still works fine and produces the correct output. - There's no problem with UVue when we run the following command:
npm run ssr:build && npm run ssr:start. - If, in the reproduction step 1.i.b (1.1.2) we do NOT select TypeScript, then UVue and
ssr:servescript work just fine.
Additional context
Please indicate versions of:
- node: v14.15.1
- npm: 7.5.4
- vue-cli: @vue/cli 4.5.11
- uvue:
- @uvue/core: 0.1.7
- @uvue/server: 0.1.7
- @uvue/vue-cli-plugin-ssr: 0.1.7
- @uvue/rquery: 0.1.7
- OS: macOS Big Sur 11.2.2 (20D80)
- Browser:
- Google Chrome Dev: 90.0.4427.5
- Firefox Developer Edition: 90.0.4427.5
- Sizzy: 51.0.0
Strange as heck, but my exhaustive research on this problem showed that running either rm -rf ./node-modules && rm ./package-lock.json && npm install or npm update solves the problem every single time.
More than 4 hours of digging through the source code and I found a solution by accident... Would love to know which exact package causes this problem but the diff log is too long for me, sorry 😃
Seems to be a problem with latest version of Vue CLI and NPM... I've no issue with Yarn actually.
Vue CLI require @vue/compiler-sfc which require Vue 3, but project use Vue 2... bit strange, I'll try to investigate on this!