universal-vue / uvue

Vue CLI plugin to create universal Vue applications with ease
https://universal-vue.github.io/docs/
MIT License
127 stars 13 forks source link

Have the same babel plugins enabled as in Vue CLI #61

Open davidyuk opened 3 years ago

davidyuk commented 3 years ago

Describe the bug Vue CLI has a richer set of Babel features than Uvue supports, we have to manually add missed features otherwise server failing with a message:

✔ Client
  Compiled successfully in 21.96s

✖ Server
  Compiled with some errors in 20.21s

 DONE  Compiled successfully in 21970ms                                                                                            5:02:08 PM

 I  Server is running: http://localhost:8080
 I  Type "rs" to restart server
[1613656928782] INFO  (17507 on Deniss-MacBook-Pro.local): Server listening: http://localhost:8080
[1613657140826] ERROR (17507 on Deniss-MacBook-Pro.local): Module parse failed: Unexpected token (392:178)
File was processed with these loaders:
 * ./node_modules/cache-loader/dist/cjs.js
 * ./node_modules/babel-loader/lib/index.js
 * ./node_modules/cache-loader/dist/cjs.js
 * ./node_modules/vue-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|       var _this$tokenInfo$this$;
| 
>       const decimals = ((_this$tokenInfo$this$ = this.tokenInfo[this.data.tokenAddress]) === null || _this$tokenInfo$this$ === void 0 ? void 0 : _this$tokenInfo$this$.decimals) ?? 18;
|       const initialPrice = new BigNumber(aeToAtoms(1)); // currently supports only hardcoded 1AE
| 
    Error: Module parse failed: Unexpected token (392:178)

To Reproduce Try to run vue-cli-service ssr:serve on a project that uses optional chaining or nullish coalescing.

Expected behavior To have Babel features enabled in Uvue out of the box, corresponding to the Vue CLI setup.

Additional context We have to add patches like this one as a workaround.

Please indicate versions of:

node: 14.15.4
vue-cli: 4.2.0
uvue: 0.1.7
os: MacOS 11.2.1
browser: -
yabab-dev commented 3 years ago

Thank for reporting this issue!

Actually your workaround seems the best way to handle it. In fact UVue makes a specific build with Babel for Node environment, and that build do not include these babel plugins automatically

For future users coming, here the workaround, in babel.config.js :


module.exports = {
  presets: [
    '@vue/cli-plugin-babel/preset',
  ],
  plugins: [
    '@babel/plugin-proposal-optional-chaining',
    '@babel/plugin-proposal-nullish-coalescing-operator',
  ],
};

I keep this open in case I find a solution