2
votes

I'm trying to implement an i18n react library by following this tutorial I got to the step

  • Alright, now when we run npm run build we should see build/locales/data.json which combines all of our JSON files into one.

And since then I can not get npm run build to work. I fix one error and another one appears. I am guessing that it's babel/webpack problems, since I have no experience with them and the tutorial had some older babel syntax errors that I managed with.

Here is my package.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/"
        }
      ]
    ]
  }
}

And here is the error:

/yadayada/node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/esm/defineProperty.js:1 (function (exports, require, module, __filename, __dirname) { export default function _defineProperty(obj, key, value) { ^^^^^^

SyntaxError: Unexpected token export at createScript (vm.js:80:10) at Object.runInThisContext (vm.js:139:10) at Module._compile (module.js:616:28) at Module._compile (/yadayada/node_modules/pirates/lib/index.js:99:24) at Module._extensions..js (module.js:663:10) at Object.newLoader [as .js] (/yadayada/node_modules/pirates/lib/index.js:104:7) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Module.require (module.js:596:17)

2
My build (30 Aug 2019) is complaining about defineProperty.js being missing. Something definitely strange here. Also using react i18-next. - emrys57

2 Answers

0
votes

In a similar i18n React project, I saw a similar obscure problem with defineProperty.js.

This package was updated to version 9.0.1 about a month ago. Installing the previous version fixed the problem for me:

npm install [email protected]
0
votes

I have faced this issue like a dozen times, here is how I solve it 1- start your terminal as administrator (or write sudo before the command) 2- try to clear the cache npm cache clear --force 3- try to npm install and hopefully it will work