简体   繁体   English

Vue 模块解析失败:意外的令牌

[英]Vue Module parse failed: Unexpected token

When I install project dependency from local directory当我从本地目录安装项目依赖项时

npm install ../myDep

and next run npm run serve everything is ok.接下来运行npm run serve一切正常。

But when I install this dependency directly from repo但是当我直接从 repo 安装这个依赖项时

( npm install git+ssh://(...)/myDep.git ) (it should be done in this way) ( npm install git+ssh://(...)/myDep.git ) (应该是这样的)

and run npm run serve I have an error:并运行npm run serve我有一个错误:

Module parse failed: Unexpected token (14:9)
You may need an appropriate loader to handle this file type.
|   }
| 
>   device = {
| 
|     info: () => {

Here is part of file with this error:这是出现此错误的文件的一部分:

export class MyDependencyClass {

  constructor(args) {
    (...)
  }

  device = {

    info: () => {
      return {};
    },  

    (...)
  }

  (...)
}

This unexpected token is = and only when I install it from repo.这个意外的令牌是=并且仅当我从 repo 安装它时。

How can I fix it?我该如何解决?

@edit package.json @edit package.json

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint",
    "deploy": "./deploy.sh",
  },
  "dependencies": {
    "core-js": "^3.3.2",
    "myDep": "git+ssh://git@gitlab.com:pplaczek/myDep.git",
    "markdown-it-vue": "^1.0.10",
    "roboto-fontface": "*",
    "vue": "^2.6.10",
    "vue-router": "^3.1.3",
    "vue-the-mask": "^0.11.1",
    "vuetify": "^2.1.0",
    "vuex": "^3.0.1"
  },
  "devDependencies": {
    "@mdi/font": "^3.9.97",
    "@vue/cli-plugin-babel": "^4.0.0",
    "@vue/cli-plugin-eslint": "^4.0.0",
    "@vue/cli-service": "^4.0.0",
    "@vue/eslint-config-prettier": "^5.0.0",
    "babel-eslint": "^10.0.3",
    "eslint": "^5.16.0",
    "eslint-plugin-prettier": "^3.1.1",
    "eslint-plugin-vue": "^5.0.0",
    "node-sass": "^4.12.0",
    "prettier": "^1.18.2",
    "sass": "^1.19.0",
    "sass-loader": "^8.0.0",
    "vue-cli-plugin-vuetify": "^2.0.2",
    "vue-template-compiler": "^2.6.10",
    "vuetify-loader": "^1.3.0"
  }
}

vue.config.js vue.config.js

module.exports = {
  transpileDependencies: ["vuetify"]
};

babel.config.js babel.config.js

module.exports = {
  presets: ["@vue/cli-plugin-babel/preset"]
};

There is no guarantee this will help, but you can try with the following Babel configuration:不能保证这会有所帮助,但您可以尝试使用以下 Babel 配置:

module.exports = {
  presets: [
    [
      '@vue/app',
      {
        exclude:
        [
          "@babel/plugin-transform-typeof-symbol",
          '@babel/plugin-transform-regenerator',
        ],
        modules: false
      }
    ]
  ],
  plugins:
  [
    "@babel/plugin-proposal-class-properties", // this seems to be the important one
  ]
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM