programing

Vuex의 확산 연산자가 babel로 올바르게 컴파일되지 않아 모듈 구축에 계속 실패함

prostudy 2022. 7. 3. 09:00
반응형

Vuex의 확산 연산자가 babel로 올바르게 컴파일되지 않아 모듈 구축에 계속 실패함

mapGetters 개체에서 확산 연산자를 사용하고 있습니다.ES6를 올바르게 컴파일하려면 특정 babel-preset-stage를 사용해야 한다는 것을 알고 있습니다.npm이 babel-preset-stage-2를 설치했는데도 이 에러가 발생하고 있습니다.

ERROR in ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/AnotherResult.vue
Module build failed: SyntaxError: Unexpected token (13:8)

  11 | export default {
  12 |     computed: {
> 13 |         ...mapGetters ([
     |         ^
  14 |             'doubleCounter',
  15 |             'stringCounter'
  16 |     ])

GITHUB를 살펴보니, 이것은 일반적인 문제인 것 같고, 사람들이 babel-preset-stage-3와 다른 webpack 설정을 시도해 볼 것을 제안하고 있는 것 같습니다.

여기 제 소포가 있습니다.json

{
  "name": "vue-cli",
  "description": "A Vue.js project",
  "author": "Maximilian Schwarzmüller <mblacky0@gmail.com>",
  "private": true,
  "scripts": {
    "dev": "cross-env NODE_ENV=development webpack-dev-server --open --inline --hot",
    "build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
  },
  "dependencies": {
    "bootstrap": "^3.3.7",
    "vue": "^2.0.1",
    "vue-router": "^2.0.1",
    "vuex": "^3.1.1"
  },
  "devDependencies": {
    "babel-core": "^6.0.0",
    "babel-loader": "^6.0.0",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-es2015": "^6.0.0",
    "babel-preset-stage-2": "^6.24.1",
    "babel-preset-stage-3": "^6.24.1",
    "cross-env": "^3.0.0",
    "css-loader": "^0.25.0",
    "file-loader": "^0.9.0",
    "vue-loader": "^9.7.0",
    "webpack": "2.1.0-beta.25",
    "webpack-dev-server": "2.1.0-beta.0"
  }
}

.babelrc 파일

{
    "presets": [
        ["es2015", {"modules": false}],
        ["stage-3", "env"]
    ],
    "plugins": ["transform-object-rest-spread"]
}

이러한 새로운 구성에서는 컴파일을 하고 싶지 않습니다.어떤 통찰이라도 있으면 고맙겠어요?

고마워요.

이 설정을 사용하여 작업을 시도합니다.

babel.rc:

{
  "presets": [
    ["es2015", { "modules": false }],
    ["stage-2"]
  ]
}

패키지.json

"devDependencies": {
    "babel-core": "^6.0.0",
    "babel-loader": "^6.0.0",
    "babel-preset-es2015": "^6.0.0",
    "babel-preset-stage-2": "^6.24.1",
    "cross-env": "^3.0.0",
    "css-loader": "^0.25.0",
    "file-loader": "^0.9.0",
    "vue-loader": "^9.7.0",
    "webpack": "2.1.0-beta.25",
    "webpack-dev-server": "2.1.0-beta.0"
  }

webpack.config.syslog

{
        test: /\.js$/,
        loader: 'babel',
        exclude: /node_modules/
      }

언급URL : https://stackoverflow.com/questions/56052239/spread-operator-in-vuex-not-compiling-correctly-with-babel-i-keep-getting-modul

반응형