Vue: Why I get Unexpected token export Error on nodejs with vue cli and ssr?

Created on 8 Aug 2019  路  1Comment  路  Source: vuejs/vue

Version

2.6.10

Reproduction link

https://github.com/wizardnet972/vuecli-with-ssr

Steps to reproduce

$ Clone my github repo: git clone https://github.com/wizardnet972/vuecli-with-ssr.git

$ npm i

$ npm run build:prod && node server.js

$ open http://localhost:8080/

Here My Github repo code and this is how I create my repo:

First I create a new app using vue/cli: $ vue create vuecli-with-ssr with typescript

I edit and add the files: vue.config.js tsconfig.json server.js babel.config.js entry-client.ts entry-server.ts main.ts index.template.html

Run the project in production mode (not the dev server) : npm run build:prod && node server.js


I just created a vue project using the vue/cli v3.10.0

I add ssr to the project like vue-cli-ssr-example example.

But after I build and run the server side (nodejs) and I try to browse to http://localhost:8080:

But The following error occurs :

error during render : /
C:\sandbox3\vuecli-with-ssr\node_modules\register-service-worker\index.js:18
export function register (swUrl, hooks) {
^^^^^^

SyntaxError: Unexpected token export
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:656:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
error during render : /favicon.ico
C:\sandbox3\vuecli-with-ssr\node_modules\register-service-worker\index.js:18
export function register (swUrl, hooks) {
^^^^^^

SyntaxError: Unexpected token export
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:656:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)

Any ideas how to fix it?

Here My Github repo code and this is how I create my repo:

First I create a new app using vue/cli: $ vue create vuecli-with-ssr

image

I edit and add the files: vue.config.js tsconfig.json server.js babel.config.js entry-client.ts entry-server.ts main.ts index.template.html

Run the project in production mode (not the dev server) : npm run build:prod && npm run build:ssr && node server.js

>All comments

Hi, thanks for your interest but Github issues are for bug reports and feature requests only. You can ask questions on the forum, the Discord server or StackOverflow. This also seems to be related to setting up plugins with vue-cli, so if you find a bug, you should report it on the plugin repository or on Vue CLI repository

Was this page helpful?
0 / 5 - 0 ratings