当前位置: 首页 > 知识库问答 >
问题:

vue.js - vue 项目打包报错?

胡高朗
2023-06-21

vue 项目打包报错? 应该怎么调整?

 error  in ./src/store/modules/userStore.ts

Module parse failed: Unexpected token (30:30)
File was processed with these loaders:
 * ./node_modules/cache-loader/dist/cjs.js
 * ./node_modules/babel-loader/lib/index.js
 * ./node_modules/ts-loader/index.js
 * ./node_modules/eslint-loader/index.js
You may need an additional loader to handle the result of these loaders.
|         userInfo
|       } = user;
>       state.userId = userInfo?.id;
|       localStorage.setItem("xxxx", userInfo?.id);
|     },

 @ ./src/store/index.ts 14:40-70
 @ ./src/main.ts
 @ multi ./src/main.ts

package.json

{
  "name": "vue-x",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "test": "vue-cli-service build --mode test",
    "stage": "vue-cli-service build --mode stage",
    "test:unit": "vue-cli-service test:unit",
    "test:e2e": "vue-cli-service test:e2e",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "axios": "^0.21.1",
    "core-js": "^3.6.5",
    "echarts": "^5.1.1",
    "element-ui": "^2.4.5",
    "file-saver": "^2.0.5",
    "js-md5": "^0.7.3",
    "moment": "^2.29.1",
    "register-service-worker": "^1.7.1",
    "vue-class-component": "^7.2.3",
    "vue-json-excel": "^0.3.0",
    "vue-property-decorator": "^9.1.2",
    "vue-router": "^3.2.0",
    "vuex": "^3.4.0",
    "xlsx": "^0.17.3"
  },
  "devDependencies": {
    "@types/jest": "^24.0.19",
    "@types/mocha": "^8.0.1",
    "@types/node": "^14.14.33",
    "@typescript-eslint/eslint-plugin": "^2.33.0",
    "@typescript-eslint/parser": "^2.33.0",
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-e2e-webdriverio": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-plugin-pwa": "~4.5.0",
    "@vue/cli-plugin-router": "~4.5.0",
    "@vue/cli-plugin-typescript": "~4.5.0",
    "@vue/cli-plugin-unit-jest": "~4.5.0",
    "@vue/cli-plugin-vuex": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "@vue/eslint-config-prettier": "^6.0.0",
    "@vue/eslint-config-typescript": "^5.0.2",
    "@vue/test-utils": "^1.0.3",
    "ali-oss": "^6.13.2",
    "chromedriver": "87",
    "cssnano": "^4.1.10",
    "cssnano-preset-advanced": "^4.0.7",
    "eslint": "^6.7.2",
    "eslint-plugin-prettier": "^3.1.3",
    "eslint-plugin-vue": "^6.2.2",
    "geckodriver": "^1.20.0",
    "json-bigint": "^1.0.0",
    "node-sass": "^4.9.2",
    "postcss-aspect-ratio-mini": "^1.1.0",
    "postcss-cssnext": "^3.1.0",
    "postcss-loader": "^4.1.0",
    "postcss-px-to-viewport": "^1.1.1",
    "postcss-px-to-viewport-opt": "0.0.4",
    "postcss-viewport-units": "^0.1.6",
    "postcss-write-svg": "^3.0.1",
    "prettier": "^1.19.1",
    "sass": "^1.26.5",
    "sass-loader": "^8.0.2",
    "ts-node": "^8.10.2",
    "typescript": "~3.9.3",
    "vue": "^2.6.11",
    "vue-cli-plugin-element": "~1.0.1",
    "vue-template-compiler": "^2.6.11",
    "vuex-module-decorators": "^1.0.1",
    "wdio-chromedriver-service": "^6.0.3",
    "wdio-geckodriver-service": "^1.1.0"
  }
}

共有1个答案

令狐献
2023-06-21

基本上,看到 unexpected token,就说明你用到了某些新的语法特性,而你现在的转译工具(比如 babel)不支持。看代码应该是 ?.,也就是 optional chaining 的问题。

解决方案有两个:

  1. 整体升级依赖
  2. 加装 @babel/plugin-transform-optional-chaining
 类似资料:
  • vue项目已经使用UglifyJsPlugin进行打包压缩了,上级要求项目打包之后js文件再小点,还有什么处理办法呢? 希望大佬们能给点建议,如果可以的话,有点代码支持! 拜谢!!!

  • node_modules/vue/types/jsx.d.ts(39,7)? 这种怎么改?

  • 第一次试用 vite 来构建 vue 项目。 报错总是在同一行,其他行想加个断点都不行。 我自己觉得是 sourcemap 的原因。找官方文档增加了 sourcemap 配置。好像也没有生效。

  • 这是什么错 安装依赖包报这个

  • 单模块 maven 项目打包 在单一模块的maven项目开发中,我们通常在 src/main/resources 编写我们的配置文件,因此,在 maven 构建的时候,我们需要添加如下配置: <resources> <resource> <directory>src/main/resources</directory> <includes>

  • 本文向大家介绍vue.js项目打包上线的图文教程,包括了vue.js项目打包上线的图文教程的使用技巧和注意事项,需要的朋友参考一下 最近一直坚持每个月写一个小的vue.js 开发的项目,最后开发完成后想到很久之前给别人回答的一个问题:vue的项目如何上线,当时有千奇百怪的回答,我在想,这些人都是肿了么,vue的官方都说了,这个框架只是做了view这一层,所以并不是把这些开发完的东西直接拷贝到服务器