我有一个Vue 2.6项目,我想在我的项目中使用像可选链这样的es2020特性,但我无法使其在我的项目中工作。我遇到了以下错误。
> vue-cli-service serve
INFO Starting development server...
98% after emitting CopyPlugin
ERROR Failed to compile with 1 error 12:59:10
error in ./src/components/list/columns/lastUpdate.vue?vue&type=script&lang=js&
Module parse failed: Unexpected token (15:20)
File was processed with these loaders:
* ./node_modules/cache-loader/dist/cjs.js
* ./node_modules/babel-loader/lib/index.js
* ./node_modules/cache-loader/dist/cjs.js
* ./node_modules/vue-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| if (!this.data.ObjInst || !this.data.ObjInst.Last_Update) return '';
|
> if (this.data?.ObjInst) {
| console.log("Hello");
| }
@ ./src/components/list/columns/lastUpdate.vue?vue&type=script&lang=js& 1:0-349 1:365-368 1:370-716 1:370-716
.
.
.
.
.
@ ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=script&lang=js&
@ ./src/App.vue?vue&type=script&lang=js&
@ ./src/App.vue
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://192.168.0.21:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
我已经安装了 Babel 插件,但是仍然出现相同的错误。
npm install --save-dev @babel/plugin-proposal-optional-chaining
我已搜索但未找到相关信息。
这些是我的项目依赖项。
{
...
"dependencies": {
"core-js": "^2.6.11",
"jwt-decode": "^2.2.0",
"vue": "^2.6.12",
"vue-i18n": "^8.24.2",
"vue-multiselect": "^2.1.6",
"vue2-admin-lte": "^0.4.3",
"vue2-daterange-picker": "^0.6.1"
},
"devDependencies": {
"@kazupon/vue-i18n-loader": "^0.3.0",
"@vue/cli-plugin-babel": "^3.12.1",
"@vue/cli-plugin-eslint": "^3.12.1",
"@vue/cli-service": "^3.12.1",
"babel-eslint": "^10.1.0",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"vue-cli-plugin-i18n": "^0.6.1",
"vue-template-compiler": "^2.6.12"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"rules": {},
"parserOptions": {
"parser": "babel-eslint"
}
}
...
}
请帮忙!
@babel/plugin-proposal-optional-chaining
并没有什么帮助,因为这不影响它是否被使用。请参阅 https://cli.vuejs.org/config/#babel 和 https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/babel-preset-app#babelpreset-env 。我不会在默认的 Vue CLI 配置中遇到问题,所以问题可能特定于您的项目。 - Estus Flask