kubernetes 无法找到模块'@babel/运行时内核js 2/内核js/反射/构造'

xpcnnkqh  于 2022-11-21  发布在  Kubernetes
关注(0)|答案(1)|浏览(298)

当前行为

从Babel 6升级到7后,PR部署阶段发生错误。在本地构建中工作正常。
这是我在K8s上的pm2日志上看到的内容

Cannot find module '@babel/runtime-corejs2/core-js/reflect/construct'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Module.Hook._require.Module.require (/home/y/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:61:29)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/home/y/share/node/manhattan_app/transpile/lib/errorHelper.js:3:26)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)

这是从package.json中摘录的内容

"devDependencies": {
    "@babel/cli": "^7.0.0",
    "@babel/core": "^7.0.0",
    "@babel/node": "^7.0.0",
    "@babel/plugin-proposal-class-properties": "^7.0.0",
    "@babel/plugin-proposal-decorators": "^7.0.0",
    "@babel/plugin-proposal-do-expressions": "^7.0.0",
    "@babel/plugin-proposal-export-default-from": "^7.0.0",
    "@babel/plugin-proposal-export-namespace-from": "^7.0.0",
    "@babel/plugin-proposal-function-bind": "^7.0.0",
    "@babel/plugin-proposal-function-sent": "^7.0.0",
    "@babel/plugin-proposal-json-strings": "^7.0.0",
    "@babel/plugin-proposal-logical-assignment-operators": "^7.0.0",
    "@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
    "@babel/plugin-proposal-numeric-separator": "^7.0.0",
    "@babel/plugin-proposal-object-rest-spread": "^7.0.0",
    "@babel/plugin-proposal-optional-chaining": "^7.0.0",
    "@babel/plugin-proposal-pipeline-operator": "^7.0.0",
    "@babel/plugin-proposal-throw-expressions": "^7.0.0",
    "@babel/plugin-syntax-dynamic-import": "^7.0.0",
    "@babel/plugin-syntax-import-meta": "^7.0.0",
    "@babel/plugin-transform-computed-properties": "^7.0.0",
    "@babel/plugin-transform-modules-commonjs": "^7.13.8",
    "@babel/plugin-transform-react-constant-elements": "^7.0.0",
    "@babel/plugin-transform-react-inline-elements": "^7.0.0",
    "@babel/plugin-transform-runtime": "^7.0.0",
    "@babel/preset-env": "^7.0.0",
    "@babel/preset-react": "^7.0.0",
    "@babel/register": "^7.0.0",
    "@babel/runtime-corejs2": "7.12.5",
    "autoprefixer": "^8.6.5",
    "babel-eslint": "^10.0.2",
    "babel-jest": "^24.8.0",
    "babel-loader": "^8.0.0",
    "babel-plugin-css-modules-transform": "^1.6.2",
    "babel-plugin-import": "^1.12.2",
    "babel-plugin-lodash": "^3.3.4",
    "babel-plugin-rewire-exports": "^0.5.0",
    "clean-css-cli": "^4.1.6",
    "component_ec_nodejs_test_util": "^1.0.6",
    "css-loader": "^3.6.0",
    "deep-freeze": "0.0.1",
    "ectest-accounts": "^0.1.1656",
    "enzyme": "^3.8.0",
    "enzyme-adapter-react-16": "^1.7.1",
    "eslint": "^6.1.0",
    "eslint-config-prettier": "^6.7.0",
    "eslint-plugin-codeceptjs": "^1.0.0",
    "eslint-plugin-json": "^1.4.0",
    "eslint-plugin-prettier": "^3.1.0",
    "eslint-plugin-react": "^7.14.3",
    "eslint-plugin-react-hooks": "^1.6.1",
    "file-loader": "^6.0.0",
    "jest": "^26.6.3",
    "jest-junit": "^3.0.0",
    "mini-css-extract-plugin": "^0.10.0",
    "nodemon": "1.17.3",
    "postcss": "^7.0.32",
    "postcss-easy-import": "^3.0.0",
    "postcss-functions": "^2.1.1",
    "postcss-import": "^10.0.0",
    "postcss-loader": "^2.0.6",
    "postcss-scss": "^1.0.2",
    "postcss-simple-vars": "^4.0.0",
    "pre-commit": "^1.2.2",
    "precss": "^2.0.0",
    "prettier": "^1.19.1",
    "react-test-renderer": "^16.6.3",
    "redux-mock-store": "^1.5.3",
    "request-promise": "^4.2.2",
    "requestretry": "^3.1.0",
    "rimraf": "2.4.3",
    "saucelabs": "^1.5.0",
    "sd-s3-assets-deploy": "^0.4.1",
    "style-loader": "^1.2.1",
    "url-loader": "^0.6.2",
    "wait-for-expect": "^1.1.1",
    "wait-on": "^2.0.2",
    "wdio-screenshot": "^0.6.0",
    "webdriverio": "^4.13.1",
    "webpack": "^4.27.0",
    "webpack-bundle-analyzer": "^3.0.3",
    "webpack-cli": "^3.1.2",
    "webpack-dev-middleware": "^3.4.0",
    "webpack-hot-middleware": "^2.24.3",
    "webpack-manifest-plugin": "^2.0.4"
  },

巴别塔配置(babel.config.js、.babelrc、包.json#巴别塔、cli命令、.eslintrc)

  • 文件名:babelrc
{
    "presets": [
      "@babel/preset-react",
      [
        "@babel/preset-env",
        {
          "targets": {
            "node": "current",
            "browsers": [
              "ie >= 11"
            ]
          }
        }
      ]
    ],
    "plugins": [
      [
        "css-modules-transform",
        {
          "generateScopedName": "[local]__[hash:base64:5]",
          "extensions": [
            ".css"
          ],
          "processorOpts": "./babel/processor.options.js"
        }
      ],
      [
        "@babel/plugin-transform-runtime",
        {
          "corejs": 2,
          "regenerator": true
        }
      ],
      "@babel/plugin-transform-computed-properties",
      "@babel/plugin-proposal-object-rest-spread",
      "@babel/plugin-proposal-class-properties",
      "@babel/plugin-transform-react-inline-elements",
      "@babel/plugin-transform-react-constant-elements",
      "lodash",
      "@babel/plugin-syntax-dynamic-import",
      "@babel/plugin-syntax-import-meta",
      "@babel/plugin-proposal-json-strings",
      [
        "@babel/plugin-proposal-decorators",
        {
          "legacy": true
        }
      ],
      "@babel/plugin-proposal-function-sent",
      "@babel/plugin-proposal-export-namespace-from",
      "@babel/plugin-proposal-numeric-separator",
      "@babel/plugin-proposal-throw-expressions",
      "@babel/plugin-proposal-export-default-from",
      "@babel/plugin-proposal-logical-assignment-operators",
      "@babel/plugin-proposal-optional-chaining",
      [
        "@babel/plugin-proposal-pipeline-operator",
        {
          "proposal": "minimal"
        }
      ],
      "@babel/plugin-proposal-nullish-coalescing-operator",
      "@babel/plugin-proposal-do-expressions",
      "@babel/plugin-proposal-function-bind"
    ],
    "sourceType": "unambiguous"
  }

环境

  • 巴别塔版本:[第七节]
  • 节点/npm版本:[例如,节点10.21.0/npm 6.14.4]
  • 操作系统:[macOS 10.15.7]
  • 莫诺雷波:[否]
  • 你如何使用巴别塔:[网络包]
    为了解决这个问题,我已经绞尽脑汁好几天了。请建议如何解决这个问题。谢谢。
ljsrvy3e

ljsrvy3e1#

因为此配置

[
        "@babel/plugin-transform-runtime",
        {
          "corejs": 2, //here
          "regenerator": true
        }
      ],

npm install --save @babel/runtime-corejs2根据巴别塔文件

相关问题