0

Update
It turns out the issue is related to the used boilerplate. A workaround is to not extract the TypeScript file, but instead keep it in the .vue file for now.

I'm getting this error in a simple Vue test project:

ERROR  Failed to compile with 1 errors
error  in ./src/App.ts
Syntax Error: Unexpected token (11:7)

It is basically the default project you get when running:

vue init Toilal/vue-webpack-template my-project

The specific code that fails:

@Component
export default class HelloWorld extends Vue {

  @Prop({ default: 'default ToDo' })
  todo: string; // unexpected token

  name = "test9"; // fine
}

Everything else seems to be working fine and I did not see anyone complain about ':' being an unexpected token on my search for answers. One guy had that issue about 2 years ago and fixed it by using a new npm version, but I am obviously on a much never version anyways.

These are the dependency sections from my package.json as I guess my issue is with some odd library combination?

"dependencies": {
  "vue": "^2.5.2",
  "vue-class-component": "^6.0.0",
  "vue-property-decorator": "^6.0.0"
},
"devDependencies": {
  "@types/node": "^6.0.10",
  "autoprefixer": "^7.1.2",
  "babel-core": "^6.22.1",
  "babel-helper-vue-jsx-merge-props": "^2.0.3",
  "babel-loader": "^7.1.1",
  "babel-plugin-syntax-jsx": "^6.18.0",
  "babel-plugin-transform-class-properties": "^6.24.1",
  "babel-plugin-transform-decorators-legacy": "^1.3.4",
  "babel-plugin-transform-runtime": "^6.22.0",
  "babel-plugin-transform-vue-jsx": "^3.5.0",
  "babel-preset-env": "^1.3.2",
  "babel-preset-stage-2": "^6.22.0",
  "chalk": "^2.0.1",
  "copy-webpack-plugin": "^4.0.1",
  "css-loader": "^0.28.0",
  "eventsource-polyfill": "^0.9.6",
  "extract-text-webpack-plugin": "^3.0.0",
  "file-loader": "^1.1.4",
  "fork-ts-checker-webpack-plugin": "^0.3.0",
  "friendly-errors-webpack-plugin": "^1.6.1",
  "html-webpack-plugin": "^2.30.1",
  "node-notifier": "^5.1.2",
  "optimize-css-assets-webpack-plugin": "^3.2.0",
  "ora": "^1.2.0",
  "portfinder": "^1.0.13",
  "postcss-import": "^11.0.0",
  "postcss-loader": "^2.0.8",
  "postcss-url": "^7.2.1",
  "raw-loader": "^0.5.1",
  "rimraf": "^2.6.0",
  "semver": "^5.3.0",
  "shelljs": "^0.7.6",
  "ts-loader": "^2.0.3",
  "typescript": "^2.6.2",
  "uglifyjs-webpack-plugin": "^1.1.1",
  "url-loader": "^0.5.8",
  "vue-loader": "^13.3.0",
  "vue-style-loader": "^3.0.1",
  "vue-template-compiler": "^2.5.2",
  "webpack": "^3.6.0",
  "webpack-bundle-analyzer": "^2.9.0",
  "webpack-dev-server": "^2.9.1",
  "webpack-merge": "^4.1.0"
}

3 Answers 3

2

Make sure that you specified TypeScript in the script tag

<script lang="ts">
    ...
</script>
Sign up to request clarification or add additional context in comments.

Comments

0

default is a preserved keyword in vue, try with something else., even in js it should be used inside switch case to return something or for exporting data

2 Comments

in that place it is actually required for it to work. As it turns out the issue is with the boilerplate i used, a workaround is possible for now.
Works perfectly fine with default without quotes for me.
0

Wrap default in quotes:

@Prop({ 'default': 'default ToDo' })

1 Comment

Works perfectly fine with default without quotes for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.