Skip to content

Why I get Unexpected token export Error on nodejs with vue cli and ssr? #10370

@wizardnet972

Description

@wizardnet972

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions