webpack babel预设React应用程序/节点模块/@babel/运行时/助手/esm/定义属性.js:1语法错误:createScript(vm.js:80:10)时导出意外令牌

e5njpo68  于 2022-12-29  发布在  Webpack
关注(0)|答案(3)|浏览(153)

我正尝试按照this tutorial来实现i18n react library,我已到达步骤

  • 好了,现在当我们运行npm run build时,我们应该看到build/locales/data.json,它将所有JSON文件合并为一个文件。

从那以后我就不能运行npm了,我修复了一个错误,又出现了另一个错误,我猜是babel/webpack的问题,因为我对它们没有经验,而且教程中有一些旧的babel语法错误,我已经处理过了。
这是我的包. json

{
    "dependencies": {
    "@babel/core": "7.4.3",
    "@babel/preset-env": "^7.5.4",
    "@babel/preset-react": "^7.0.0",
    "@babel/runtime": "^7.5.4",
    "@svgr/webpack": "4.1.0",
    "@typescript-eslint/eslint-plugin": "1.6.0",
    "@typescript-eslint/parser": "1.6.0",
    "babel-eslint": "10.0.1",
    "babel-jest": "^24.8.0",
    "babel-loader": "8.0.5",
    "babel-plugin-named-asset-import": "^0.3.2",
    "babel-plugin-react-intl": "^4.1.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-react-app": "^9.0.0",
    "bootstrap": "^4.3.1",
    "camelcase": "^5.2.0",
    "case-sensitive-paths-webpack-plugin": "2.2.0",
    "css-loader": "2.1.1",
    "dotenv": "6.2.0",
    "dotenv-expand": "4.2.0",
    "eslint": "^5.16.0",
    "eslint-config-react-app": "^4.0.1",
    "eslint-loader": "2.1.2",
    "eslint-plugin-flowtype": "2.50.1",
    "eslint-plugin-import": "2.16.0",
    "eslint-plugin-jsx-a11y": "6.2.1",
    "eslint-plugin-react": "7.12.4",
    "eslint-plugin-react-hooks": "^1.5.0",
    "file-loader": "3.0.1",
    "firebase": "^6.2.4",
    "fs-extra": "7.0.1",
    "html-webpack-plugin": "4.0.0-beta.5",
    "identity-obj-proxy": "3.0.0",
    "is-wsl": "^1.1.0",
    "jest": "24.7.1",
    "jest-environment-jsdom-fourteen": "0.1.0",
    "jest-resolve": "24.7.1",
    "jest-watch-typeahead": "0.3.0",
    "mini-css-extract-plugin": "0.5.0",
    "optimize-css-assets-webpack-plugin": "5.0.1",
    "pnp-webpack-plugin": "1.2.1",
    "postcss-flexbugs-fixes": "4.1.0",
    "postcss-loader": "3.0.0",
    "postcss-normalize": "7.0.1",
    "postcss-preset-env": "6.6.0",
    "postcss-safe-parser": "4.0.1",
    "react": "^16.8.6",
    "react-app-polyfill": "^1.0.1",
    "react-dev-utils": "^9.0.1",
    "react-dom": "^16.8.6",
    "react-intl": "^2.9.0",
    "react-router-dom": "^5.0.1",
    "reactstrap": "^8.0.1",
    "resolve": "1.10.0",
    "sass-loader": "7.1.0",
    "semver": "6.0.0",
    "style-loader": "0.23.1",
    "terser-webpack-plugin": "1.2.3",
    "ts-pnp": "1.1.2",
    "url-loader": "1.1.2",
    "webpack": "4.29.6",
    "webpack-dev-server": "3.2.1",
    "webpack-manifest-plugin": "2.0.4",
    "workbox-webpack-plugin": "4.2.0"
  },
  "devDependencies": {
    "@babel/cli": "^7.5.0",
    "@babel/node": "^7.5.0",
    "@babel/plugin-transform-runtime": "^7.5.0"
  },
  "scripts": {
    "start": "node scripts/start.js",
    "test": "node scripts/test.js",
    "build:langs": "NODE_ENV='production' babel-node scripts/mergeMessages.js",
    "build": "npm run build:langs && node scripts/build.js"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
  },
  "babel": {
    "presets": [
      "react-app",
      "@babel/preset-env",
      "@babel/preset-react"
    ],
    "passPerPreset": false,
    "plugins": [
      [
        "@babel/plugin-transform-runtime"
      ],
      [
        "react-intl",
        {
          "messagesDir": "./public/messages/"
        }
      ]
    ]
  }
}

这里是错误:
/yadayada/节点模块/babel预设React应用程序/节点模块/@babel/运行时/助手/esm/定义属性. js:1(函数(导出,要求,模块,__文件名,__目录名){导出默认函数定义属性(对象,键,值){^^^^^
语法错误:在对象的createScript(vm. js:80:10)处导出意外标记。在模块的runInThisContext(vm. js:139:10)处导出意外标记。在模块的_compile(模块. js:616:28)处导出意外标记。在模块._extensions.. js(模块. js:663:10)处导出意外标记。在对象的newLoader [as. js](/yadayada/node_modules/pirates/lib/index. js:104:7)处导出意外标记。在函数的模块的tryModuleLoad(模块. js:505:12)处导出意外标记。在模块的_load(模块. js:497:3)处导出意外标记。在模块的require(模块. js:596:17)处导出意外标记。

am46iovg

am46iovg1#

在一个类似的i18n React项目中,我发现defineProperty.js也存在类似的模糊问题。
这个软件包大约一个月前更新到了9. 0. 1版本。安装以前的版本为我修复了这个问题:

npm install babel-preset-react-app@9.0.0
56lgkhnf

56lgkhnf2#

我已经遇到过这个问题十几次了,下面是我解决它的方法1-以管理员身份启动您的终端(或在命令前写入sudo)2-尝试清除该高速缓存npm cache clear --force 3-尝试npm install,希望它能工作

8i9zcol2

8i9zcol23#

我通过删除.next文件夹并重新启动应用程序来解决此错误:)。

相关问题