0

什么地方出了错?

Babel 从 7.x 迁移到 8.x 节点从 8.x 迁移到 10.x

你用的是什么配置?

将 .babelrc 中的目标从 8.10 更改为 10.14.1 将 serverless.yml 中的运行时从 8.10 更改为运行时:nodejs10.14.1

您看到了来自您的提供商的哪些堆栈跟踪或错误消息?

ERROR in ./getCaseRecord.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Plugin/Preset files are not allowed to export objects, only functions. In /Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-preset-stage-3/lib/index.js
    at createDescriptor (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-descriptors.js:178:11)
    at items.map (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-descriptors.js:109:50)
    at Array.map (<anonymous>)
    at createDescriptors (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
    at createPresetDescriptors (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-descriptors.js:101:10)
    at presets (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-descriptors.js:47:19)
    at mergeChainOpts (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-chain.js:320:26)
    at /Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-chain.js:283:7
    at buildRootChain (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-chain.js:120:22)
    at loadPrivatePartialConfig (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/partial.js:85:55)
    at Object.loadPartialConfig (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/partial.js:110:18)
    at Object.<anonymous> (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:144:26)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:3:103)
    at _next (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:5:194)
    at /Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:5:364
    at new Promise (<anonymous>)
    at Object.<anonymous> (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:5:97)
    at Object._loader (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:224:18)
    at Object.loader (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:60:18)
    at Object.<anonymous> (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:55:12)

这是我的.babelrc文件中的内容:

{
    "plugins": [],
    "presets": [
        ["env", {"node": "10.14.1"}],
        "stage-3"
    ]
}

这是我的依赖项package.json

"devDependencies": {
    "aws-sdk": "^2.350.0",
    "babel-core": "^6.26.3",
    "babel-eslint": "^10.0.1",
    "babel-loader": "^8.0.6",
    "babel-plugin-source-map-support": "^2.0.1",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-stage-3": "^6.24.1",
    "eslint": "^5.15.0",
    "eslint-config-standard": "^12.0.0",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-node": "^9.1.0",
    "eslint-plugin-promise": "^4.0.1",
    "eslint-plugin-react": "^7.12.4",
    "eslint-plugin-standard": "^4.0.0",
    "jest": "^24.8.0",
    "serverless-offline": "^5.0.0",
    "serverless-webpack": "^5.1.0",
    "webpack": "^4.16.2",
    "webpack-node-externals": "^1.6.0"
  },

你怎么看?如果可能的话,我真的很想保持最新状态并使用最新版本的 babel。有人知道 serverless-webpack 是否支持 babel.v8 吗?

如果是这样,考虑到上述信息,我怎样才能让他们一起工作?

谢谢!

4

1 回答 1

0

以防万一它有帮助,我能让它工作的唯一方法就是这样评论babel-loader

module: {
    rules: [
      {
        test: /\.js$/,
        // TODO: This was the fix to sls deploy
        // loader: "babel-loader",
        include: __dirname,
        exclude: /node_modules/
      }
    ]
  }

不确定这是否是最好的解决方法,但它帮助我解决了我正在处理的当前问题。

于 2019-06-12T18:09:50.450 回答